Source code for naginterfaces.library.pde

# -*- coding: utf-8 -*-
r"""
Module Summary
--------------
Interfaces for the NAG Mark 27.3 `pde` Chapter.

``pde`` - Partial Differential Equations

This module is concerned with the numerical solution of partial differential equations.

See Also
--------
``naginterfaces.library.examples.pde`` :
    This subpackage contains examples for the ``pde`` module.
    See also the :ref:`library_pde_ex` subsection.

Functionality Index
-------------------

**Automatic mesh generation**

  triangles over a plane domain: :meth:`dim2_triangulate`

**Black--Scholes equation**

  analytic: :meth:`dim1_blackscholes_closed`

  finite difference: :meth:`dim1_blackscholes_fd`

**Convection-diffusion system(s)**

  nonlinear

    one space dimension

      using upwind difference scheme based on Riemann solvers: :meth:`dim1_parab_convdiff`

**Elliptic equations**

  discretization on rectangular grid (seven-point two-dimensional molecule): :meth:`dim2_ellip_discret`

  equations on rectangular grid (seven-point two-dimensional molecule): :meth:`dim2_ellip_mgrid`

  finite difference equations (five-point two-dimensional molecule): :meth:`dim2_ellip_fd`

  finite difference equations (seven-point three-dimensional molecule): :meth:`dim3_ellip_fd`

  Helmholtz's equation in three dimensions: :meth:`dim3_ellip_helmholtz`

  Laplace's equation in two dimensions: :meth:`dim2_laplace`

**First-order system(s)**

  nonlinear

    one space dimension

      using Keller box scheme: :meth:`dim1_parab_keller`

**PDEs, general system, one space variable, method of lines**

  parabolic

    collocation spatial discretization

      coupled DAEs, comprehensive: :meth:`dim1_parab_dae_coll`

      easy-to-use: :meth:`dim1_parab_coll`

    finite differences spatial discretization

      coupled DAEs, comprehensive: :meth:`dim1_parab_dae_fd`

      coupled DAEs, remeshing, comprehensive: :meth:`dim1_parab_remesh_fd`

      easy-to-use: :meth:`dim1_parab_fd`

**Second order system(s)**

  nonlinear

    two space dimensions

      in rectangular domain: :meth:`dim2_gen_order2_rectangle`

      in rectilinear domain: :meth:`dim2_gen_order2_rectilinear`

**Utility function**

  average values for :meth:`dim1_blackscholes_closed`: :meth:`dim1_blackscholes_means`

  basic SIP for five-point two-dimensional molecule: :meth:`dim2_ellip_fd_iter`

  basic SIP for seven-point three-dimensional molecule: :meth:`dim3_ellip_fd_iter`

  exact Riemann solver for Euler equations: :meth:`dim1_parab_euler_exact`

  HLL Riemann solver for Euler equations: :meth:`dim1_parab_euler_hll`

  interpolation function for collocation scheme: :meth:`dim1_parab_coll_interp`

  interpolation function for finite difference

    Keller box and upwind scheme: :meth:`dim1_parab_fd_interp`

  Osher's Riemann solver for Euler equations: :meth:`dim1_parab_euler_osher`

  return coordinates of grid points for :meth:`dim2_gen_order2_rectilinear`: :meth:`dim2_gen_order2_rectilinear_extractgrid`

  Roe's Riemann solver for Euler equations: :meth:`dim1_parab_euler_roe`

For full information please refer to the NAG Library document

https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03intro.html
"""

# NAG Copyright 2017-2021.

[docs]def dim2_laplace(stage1, ext, dorm, p, q, x, y, phi, phid, alpha): r""" ``dim2_laplace`` solves Laplace's equation in two dimensions for an arbitrary domain bounded internally or externally by one or more closed contours, given the value of either the unknown function or its normal derivative (into the domain) at each point of the boundary. .. _d03ea-py2-py-doc: For full information please refer to the NAG Library document for d03ea https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03eaf.html .. _d03ea-py2-py-parameters: **Parameters** **stage1** : bool Indicates whether the function call is for stage :math:`1` of the computation as defined in :ref:`Notes <d03ea-py2-py-notes>`. :math:`\mathrm{stage1} = \mathbf{True}` The call is for stage :math:`1`. :math:`\mathrm{stage1} = \mathbf{False}` The call is for stage :math:`2`. **ext** : bool The form of the domain. If :math:`\mathrm{ext} = \mathbf{True}`, the domain is unbounded. Otherwise the domain is an interior one. **dorm** : bool The form of the boundary conditions. If :math:`\mathrm{dorm} = \mathbf{True}`, the problem is a Dirichlet or mixed boundary value problem. Otherwise it is a Neumann problem. **p** : float To stage :math:`2`, :math:`\mathrm{p}` and :math:`\mathrm{q}` must specify the :math:`x` and :math:`y` coordinates respectively of a point at which the solution is required. When :math:`\mathrm{stage1}` is :math:`\mathbf{True}`, :math:`\mathrm{p}` and :math:`\mathrm{q}` are ignored. **q** : float To stage :math:`2`, :math:`\mathrm{p}` and :math:`\mathrm{q}` must specify the :math:`x` and :math:`y` coordinates respectively of a point at which the solution is required. When :math:`\mathrm{stage1}` is :math:`\mathbf{True}`, :math:`\mathrm{p}` and :math:`\mathrm{q}` are ignored. **x** : float, array-like, shape :math:`\left(\textit{n1p1}\right)` The :math:`x` and :math:`y` coordinates respectively of points on the one or more closed contours which define the domain of the problem. Note: each contour is described in such a manner that the subscripts of the coordinates increase when the domain is kept on the left. The final point on each contour coincides with the first and, if a further contour is to be described, the coordinates of this point are repeated in the arrays. In this way each interval is defined by three points, the second of which (the nodal point) always has an even subscript. In the case of the interior Neumann problem, the outermost boundary contour must be given first, if there is more than one. **y** : float, array-like, shape :math:`\left(\textit{n1p1}\right)` The :math:`x` and :math:`y` coordinates respectively of points on the one or more closed contours which define the domain of the problem. Note: each contour is described in such a manner that the subscripts of the coordinates increase when the domain is kept on the left. The final point on each contour coincides with the first and, if a further contour is to be described, the coordinates of this point are repeated in the arrays. In this way each interval is defined by three points, the second of which (the nodal point) always has an even subscript. In the case of the interior Neumann problem, the outermost boundary contour must be given first, if there is more than one. **phi** : float, array-like, shape :math:`\left(n\right)` For stage :math:`1`, :math:`\mathrm{phi}` must contain the nodal values of :math:`\phi` or its normal derivative (into the domain) as prescribed in each interval. For stage :math:`2` it must retain its output values from stage :math:`1`. **phid** : float, array-like, shape :math:`\left(n\right)` For stage :math:`1`, :math:`\mathrm{phid}[\textit{i}-1]` must hold the value :math:`0.0` or :math:`1.0` accordingly as :math:`\mathrm{phi}[\textit{i}-1]` contains a value of :math:`\phi` or its normal derivative, for :math:`\textit{i} = 1,2,\ldots,n`. For stage :math:`2` it must retain its output values from stage :math:`1`. **alpha** : float For stage :math:`1`, the use of :math:`\mathrm{alpha}` depends on the nature of the problem: if :math:`\mathrm{dorm} = \mathbf{True}`, :math:`\mathrm{alpha}` need not be set; if :math:`\mathrm{dorm} = \mathbf{False}` and :math:`\mathrm{ext} = \mathbf{True}`, :math:`\mathrm{alpha}` must contain the prescribed constant :math:`c` (see :ref:`Notes <d03ea-py2-py-notes>`); if :math:`\mathrm{dorm} = \mathbf{False}` and :math:`\mathrm{ext} = \mathbf{False}`, :math:`\mathrm{alpha}` must contain an appropriate value (often zero) for the integral of :math:`\phi` around the outermost boundary. For stage :math:`2`, on every call :math:`\mathrm{alpha}` must contain the value returned at stage :math:`1`. **Returns** **phi** : float, ndarray, shape :math:`\left(n\right)` From stage :math:`1`, it contains the constants which approximate :math:`\phi` in each interval. It remains unchanged on exit from stage :math:`2`. **phid** : float, ndarray, shape :math:`\left(n\right)` From stage :math:`1`, :math:`\mathrm{phid}` contains the constants which approximate the normal derivative of :math:`\phi` in each interval. It remains unchanged on exit from stage :math:`2`. **alpha** : float From stage :math:`1`: if :math:`\mathrm{ext} = \mathbf{False}`, :math:`\mathrm{alpha}` contains :math:`0.0`; if :math:`\mathrm{ext} = \mathbf{True}` and :math:`\mathrm{dorm} = \mathbf{False}` :math:`\mathrm{alpha}` is unchanged; if :math:`\mathrm{ext} = \mathbf{True}` and :math:`\mathrm{dorm} = \mathbf{True}` :math:`\mathrm{alpha}` contains a computed estimate for :math:`c`. From stage :math:`2`: :math:`\mathrm{alpha}` contains the computed value of :math:`\phi` at the point (:math:`\mathrm{p}`,\ :math:`\mathrm{q}`). .. _d03ea-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) Tolerance is too small: :math:`\textit{icint}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) Tolerance is too large: :math:`\textit{icint}[0] = 0`. (`errno` :math:`2`) Incorrect rank: :math:`\textit{icint}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03ea-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_laplace`` uses an integral equation method, based upon Green's formula, which yields the solution, :math:`\phi`, within the domain, given its value or that of its normal derivative at each point of the boundary (except possibly at a finite number of discrete points). The solution is obtained in two stages. The first, which is executed once only, determines the complementary boundary values, i.e., :math:`\phi`, where its normal derivative is known and vice versa. The second stage is entered once for each point at which the solution is required. The boundary is divided into a number of intervals in each of which :math:`\phi` and its normal derivative are approximated by constants. Of these half are evaluated by applying the given boundary conditions at one 'nodal' point within each interval while the remainder are determined (in stage :math:`1`) by solving a set of simultaneous linear equations. Here this is achieved by means of auxiliary function :meth:`lapackeig.dgels <naginterfaces.library.lapackeig.dgels>`, which will yield the least squares solution of an overdetermined system of equations as well as the unique solution of a square nonsingular system. In exterior domains the solution behaves as :math:`c+s \log\left(r\right)+\mathrm{O}\left(1/r\right)` as :math:`r` tends to infinity, where :math:`c` is a constant, :math:`s` is the total integral of the normal derivative around the boundary and :math:`r` is the radial distance from the origin of coordinates. For the Neumann problem (when the normal derivative is given along the whole boundary) :math:`s` is fixed by the boundary conditions whilst :math:`c` is chosen by you. However, for a Dirichlet problem (when :math:`\phi` is given along the whole boundary) or for a mixed problem, stage :math:`1` produces a value of :math:`c` for which :math:`s = 0`; then as :math:`r` tends to infinity the solution tends to the constant :math:`c`. .. _d03ea-py2-py-references: **References** Symm, G T and Pitfield, R A, 1974, `Solution of Laplace's equation in two dimensions`, NPL Report NAC 44, National Physical Laboratory """ raise NotImplementedError
[docs]def dim2_ellip_fd(a, b, c, d, e, q, t, aparam, itmax, itcoun, ndir, ixn, iyn, conres, conchn): r""" ``dim2_ellip_fd`` uses the Strongly Implicit Procedure to calculate the solution to a system of simultaneous algebraic equations of five-point molecule form on a two-dimensional topologically-rectangular mesh. ('Topological' means that a polar grid, for example :math:`\left(r, \theta \right)`, can be used, being equivalent to a rectangular box.) .. _d03eb-py2-py-doc: For full information please refer to the NAG Library document for d03eb https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html .. _d03eb-py2-py-parameters: **Parameters** **a** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{a}[\textit{i}-1,\textit{j}-1]` must contain the coefficient of the 'southerly' term involving :math:`t_{{\textit{i},\textit{j}-1}}` in the :math:`\left(\textit{i}, \textit{j}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html#eqn1>`__, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{a}`, for :math:`j = 1`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle. **b** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{b}[\textit{i}-1,\textit{j}-1]` must contain the coefficient of the 'westerly' term involving :math:`t_{{i-1,j}}` in the :math:`\left(i, j\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html#eqn1>`__, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{b}`, for :math:`i = 1`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle. **c** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{c}[\textit{i}-1,\textit{j}-1]` must contain the coefficient of the 'central' term involving :math:`t_{{\textit{i}\textit{j}}}` in the :math:`\left(\textit{i}, \textit{j}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html#eqn1>`__, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{c}` are checked to ensure that they are nonzero. If any element is found to be zero, the corresponding algebraic equation is assumed to be :math:`t_{{\textit{i}\textit{j}}} = q_{{\textit{i}\textit{j}}}`. This feature can be used to define the equations for nodes at which, for example, Dirichlet boundary conditions are applied, or for nodes external to the problem of interest, by setting :math:`\mathrm{c}[\textit{i}-1,\textit{j}-1] = 0.0` at appropriate points, and the corresponding value of :math:`\mathrm{q}[\textit{i}-1,\textit{j}-1]` to the appropriate value, namely the prescribed value of :math:`\mathrm{t}[\textit{i}-1,\textit{j}-1]` in the Dirichlet case or zero at an external point. **d** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{d}[\textit{i}-1,\textit{j}-1]` must contain the coefficient of the 'easterly' term involving :math:`t_{{\textit{i}+1,\textit{j}}}` in the :math:`\left(\textit{i}, \textit{j}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html#eqn1>`__, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{d}`, for :math:`i = \textit{n1}`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle. **e** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{e}[\textit{i}-1,\textit{j}-1]` must contain the coefficient of the 'northerly' term involving :math:`t_{{\textit{i},\textit{j}+1}}` in the :math:`\left(\textit{i}, \textit{j}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html#eqn1>`__, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{e}`, for :math:`j = \textit{n2}` must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle. **q** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{q}[\textit{i}-1,\textit{j}-1]` must contain :math:`q_{{\textit{i}\textit{j}}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`, i.e., the source term values at the nodal points for the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ebf.html#eqn1>`__. **t** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{t}[\textit{i}-1,\textit{j}-1]` must contain the element :math:`t_{{\textit{i}\textit{j}}}` of the approximate solution to the equations supplied by the calling program as an initial starting value, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. If no better approximation is known, an array of zeros can be used. **aparam** : float The iteration acceleration factor. A value of :math:`1.0` is adequate for most typical problems. However, if convergence is slow, the value can be reduced, typically to :math:`0.2` or :math:`0.1`. If divergence is obtained, the value can be increased, typically to :math:`2.0`, :math:`5.0` or :math:`10.0`. **itmax** : int The maximum number of iterations to be used by the function in seeking the solution. A reasonable value might be :math:`30` if :math:`\textit{n1} = \textit{n2} = 10` or :math:`100` if :math:`\textit{n1} = \textit{n2} = 50`. **itcoun** : int On the first call of ``dim2_ellip_fd``, :math:`\mathrm{itcoun}` must be set to :math:`0`. On subsequent entries, its value must be unchanged from the previous call. **ndir** : int Indicates whether or not the system of equations has a unique solution. For systems which have a unique solution, :math:`\mathrm{ndir}` must be set to any nonzero value. For systems derived from, for example, Laplace's equation with all Neumann boundary conditions, i.e., problems in which an arbitrary constant can be added to the solution, :math:`\mathrm{ndir}` should be set to :math:`0` and the values of the next two arguments must be specified. For such problems the function subtracts the value of the function derived at the node (:math:`\mathrm{ixn}`, :math:`\mathrm{iyn}`) from the whole solution after each iteration to reduce the possibility of large rounding errors. You must also ensure that for such problems the appropriate consistency condition on the source terms :math:`\mathrm{q}` is satisfied. **ixn** : int Is ignored unless :math:`\mathrm{ndir}` is equal to zero, in which case it must specify the first index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest. **iyn** : int Is ignored unless :math:`\mathrm{ndir}` is equal to zero, in which case it must specify the second index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest. **conres** : float The convergence criterion to be used on the maximum absolute value of the normalized residual vector components. The latter is defined as the residual of the algebraic equation divided by the central coefficient when the latter is not equal to :math:`0.0`, and defined as the residual when the central coefficient is zero. Clearly :math:`\mathrm{conres}` should not be less than a reasonable multiple of the machine precision. **conchn** : float The convergence criterion to be used on the maximum absolute value of the change made at each iteration to the elements of the array :math:`\mathrm{t}`, namely the dependent variable. Clearly :math:`\mathrm{conchn}` should not be less than a reasonable multiple of the machine precision multiplied by the maximum value of :math:`\mathrm{t}` attained. Convergence is achieved when both the convergence criteria are satisfied. You can, therefore, set convergence on either the residual or on the change, or (as is recommended) on a requirement that both are below prescribed limits. **Returns** **t** : float, ndarray, shape :math:`\left(\textit{n1}, \textit{n2}\right)` The solution derived by the function. **itcoun** : int Its value is increased by the number of iterations used on this call (namely :math:`\mathrm{itused}`). It, therefore, stores the accumulated number of iterations actually used. For subsequent calls for the same problem, i.e., with the same :math:`\textit{n1}` and :math:`\textit{n2}` but possibly different coefficients and/or source terms, as occur with nonlinear systems or with time-dependent systems, :math:`\mathrm{itcoun}` is the accumulated number of iterations. This applies to the second and subsequent calls to ``dim2_ellip_fd``. In this way a suitable cycling of the sequence of iteration arguments is obtained in the calls to :meth:`dim2_ellip_fd_iter`. **itused** : int The number of iterations actually used on that call. **resids** : float, ndarray, shape :math:`\left(\mathrm{itmax}\right)` The maximum absolute value of the residuals calculated at the :math:`\textit{i}`\ th iteration, for :math:`\textit{i} = 1,2,\ldots,\mathrm{itused}`. If you want to know the maximum absolute residual of the solution which is returned you must calculate this in the calling program. The sequence of values :math:`\mathrm{resids}` indicates the rate of convergence. **chngs** : float, ndarray, shape :math:`\left(\mathrm{itmax}\right)` The maximum absolute value of the changes made to the components of the dependent variable :math:`\mathrm{t}` at the :math:`\textit{i}`\ th iteration, for :math:`\textit{i} = 1,2,\ldots,\mathrm{itused}`. The sequence of values :math:`\mathrm{chngs}` indicates the rate of convergence. .. _d03eb-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\textit{n2} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{n2} > 1`. (`errno` :math:`1`) On entry, :math:`\textit{n1} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{n1} > 1`. (`errno` :math:`3`) On entry, :math:`\mathrm{aparam} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{aparam} > 0.0`. (`errno` :math:`4`) On entry, :math:`\mathrm{aparam} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{n1} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{n2} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{aparam}\leq \left(\left(\textit{n1}-1\right)^2+\left(\textit{n2}-1\right)^2\right)/2`. (`errno` :math:`5`) Convergence not achieved in :math:`\mathrm{itmax}` iterations: :math:`\mathrm{itmax} = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03eb-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` Given a set of simultaneous equations .. math:: Mt = q (which could be nonlinear) derived, for example, from a finite difference representation of a two-dimensional elliptic partial differential equation and its boundary conditions, the function determines the values of the dependent variable :math:`t`. :math:`q` is a known vector of length :math:`n_1\times n_2` and :math:`M` is a square :math:`\left(n_1\times n_2\right)\times \left(n_1\times n_2\right)` matrix. The equations must be of five-diagonal form: .. math:: a_{{ij}}t_{{i,j-1}}+b_{{ij}}t_{{i-1,j}}+c_{{ij}}t_{{ij}}+d_{{ij}}t_{{i+1,j}}+e_{{ij}}t_{{i,j+1}} = q_{{ij}} for :math:`i = 1,2,\ldots,n_1` and :math:`j = 1,2,\ldots,n_2`, provided :math:`c_{{ij}}\neq 0.0`. Indeed, if :math:`c_{{ij}} = 0.0`, then the equation is assumed to be .. math:: t_{{ij}} = q_{{ij}}\text{.} For example, if :math:`n_1 = 3` and :math:`n_2 = 2`, the equations take the form: .. math:: \left[\begin{array}{llllll}c_{11}&d_{11}&&e_{11}&&\\b_{21}&c_{21}&d_{21}&&e_{21}&\\&b_{31}&c_{31}&&&e_{31}\\a_{12}&&&c_{12}&d_{12}&\\&a_{22}&&b_{22}&c_{22}&d_{22}\\&&a_{32}&&b_{32}&c_{32}\end{array}\right]\left[\begin{array}{l}t_{11}\\t_{21}\\t_{31}\\t_{12}\\t_{22}\\t_{32}\end{array}\right] = \left[\begin{array}{l}q_{11}\\q_{21}\\q_{31}\\q_{12}\\q_{22}\\q_{32}\end{array}\right]\text{.} The system is solved iteratively, from a starting approximation :math:`t^{\left(1\right)}`, by the formulae .. math:: \begin{array}{ll}r^{\left(n\right)}& = q-Mt^{\left(n\right)}\\&\\Ms^{\left(n\right)}& = r^{\left(n\right)}\\&\\t^{\left(n+1\right)}& = t^{\left(n\right)}+s^{\left(n\right)}\text{.}\end{array} Thus :math:`r^{\left(n\right)}` is the residual of the :math:`n`\ th approximate solution :math:`t^{\left(n\right)}`, and :math:`s^{\left(n\right)}` is the update change vector. The calling program supplies an initial approximation for the values of the dependent variable in the array :math:`\mathrm{t}`, the coefficients of the five-point molecule system of equations in the arrays :math:`\mathrm{a}`, :math:`\mathrm{b}`, :math:`\mathrm{c}`, :math:`\mathrm{d}` and :math:`\mathrm{e}`, and the source terms in the array :math:`\mathrm{q}`. The function derives the residual of the latest approximate solution and then uses the approximate :math:`LU` factorization of the Strongly Implicit Procedure with the necessary acceleration argument adjustment by calling :meth:`dim2_ellip_fd_iter` at each iteration. ``dim2_ellip_fd`` combines the newly derived change with the old approximation to obtain the new approximate solution for :math:`t`. The new solution is checked for convergence against the user-supplied convergence criteria and if these have not been achieved the iterative cycle is repeated. Convergence is based on both the maximum absolute normalized residuals (calculated with reference to the previous approximate solution as these are calculated at the commencement of each iteration) and on the maximum absolute change made to the values of :math:`t`. Problems in topologically non-rectangular regions can be solved using the function by surrounding the region by a circumscribing topological rectangle. The equations for the nodal values external to the region of interest are set to zero (i.e., :math:`c_{{ij}} = t_{{ij}} = 0`) and the boundary conditions are incorporated into the equations for the appropriate nodes. If there is no better initial approximation when starting the iterative cycle, an array of all zeros can be used as the initial approximation. The function can be used to solve linear elliptic equations in which case the arrays :math:`\mathrm{a}`, :math:`\mathrm{b}`, :math:`\mathrm{c}`, :math:`\mathrm{d}`, :math:`\mathrm{e}` and :math:`\mathrm{q}` are constants and for which a single call provides the required solution. It can also be used to solve nonlinear elliptic equations in which case some or all of these arrays may require updating during the progress of the iterations as more accurate solutions are derived. The function will then have to be called repeatedly in an outer iterative cycle. Dependent on the nonlinearity, some under relaxation of the coefficients and/or source terms may be needed during their recalculation using the new estimates of the solution. The function can also be used to solve each step of a time-dependent parabolic equation in two space dimensions. The solution at each time step can be expressed in terms of an elliptic equation if the Crank--Nicolson or other form of implicit time integration is used. Neither diagonal dominance, nor positive-definiteness, of the matrix :math:`M` formed from the arrays :math:`\mathrm{a}`, :math:`\mathrm{b}`, :math:`\mathrm{c}`, :math:`\mathrm{d}`, :math:`\mathrm{e}` is necessary to ensure convergence. For problems in which the solution is not unique in the sense that an arbitrary constant can be added to the solution, for example Laplace's equation with all Neumann boundary conditions, an argument is incorporated so that the solution can be rescaled by subtracting a specified nodal value from the whole solution :math:`t` after the completion of every iteration to keep rounding errors to a minimum for those cases when the convergence is slow. .. _d03eb-py2-py-references: **References** Jacobs, D A H, 1972, `The strongly implicit procedure for the numerical solution of parabolic and elliptic partial differential equations`, Note RD/L/N66/72, Central Electricity Research Laboratory Stone, H L, 1968, `Iterative solution of implicit approximations of multi-dimensional partial differential equations`, SIAM J. Numer. Anal. (5), 530--558 """ raise NotImplementedError
[docs]def dim3_ellip_fd(n2, a, b, c, d, e, f, g, q, t, aparam, itmax, itcoun, ndir, ixn, iyn, izn, conres, conchn): r""" ``dim3_ellip_fd`` uses the Strongly Implicit Procedure to calculate the solution to a system of simultaneous algebraic equations of seven-point molecule form on a three-dimensional topologically-rectangular mesh. ('Topological' means that a polar grid, for example, can be used if it is equivalent to a rectangular box.) .. _d03ec-py2-py-doc: For full information please refer to the NAG Library document for d03ec https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html .. _d03ec-py2-py-parameters: **Parameters** **n2** : int The number of nodes in the second coordinate direction, :math:`n_2`. **a** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{a}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i}\textit{j},\textit{k}-1}}` in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{a}`, for :math:`k = 1`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box. **b** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{b}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i},\textit{j}-1,\textit{k}}}` in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{b}`, for :math:`j = 1`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box. **c** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{c}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i}-1,\textit{j}\textit{k}}}` in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{c}`, for :math:`i = 1`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box. **d** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{d}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i}\textit{j}\textit{k}}}` (the 'central' term) in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{d}` are checked to ensure that they are nonzero. If any element is found to be zero, the corresponding algebraic equation is assumed to be :math:`t_{{ijk}} = q_{{ijk}}`. This feature can be used to define the equations for nodes at which, for example, Dirichlet boundary conditions are applied, or for nodes external to the problem of interest. Setting :math:`\mathrm{d}[i-1,j-1,k-1] = 0.0` at appropriate points, and the corresponding value of :math:`\mathrm{q}[i-1,j-1,k-1]` to the appropriate value, namely the prescribed value of :math:`\mathrm{t}[i-1,j-1,k-1]` in the Dirichlet case, or to zero at an external point. **e** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{e}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i}+1,\textit{j}\textit{k}}}` in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{e}`, for :math:`i = \textit{n1}`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box. **f** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{f}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i},\textit{j}+1,\textit{k}}}` in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{f}`, for :math:`j = \mathrm{n2}`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box. **g** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{g}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the coefficient of :math:`t_{{\textit{i}\textit{j},\textit{k}+1}}` in the :math:`\left(\textit{i}, \textit{j}, \textit{k}\right)`\ th equation of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{g}`, for :math:`k = \textit{n3}`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the box. **q** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{q}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain :math:`q_{{\textit{i}\textit{j}\textit{k}}}`, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`, i.e., the source-term values at the nodal points of the system `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ecf.html#eqn1>`__. **t** : float, array-like, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` :math:`\mathrm{t}[\textit{i}-1,\textit{j}-1,\textit{k}-1]` must contain the element :math:`t_{{\textit{i}\textit{j}\textit{k}}}` of an approximate solution to the equations, for :math:`\textit{k} = 1,2,\ldots,\textit{n3}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. If no better approximation is known, an array of zeros can be used. **aparam** : float The iteration acceleration factor. A value of :math:`1.0` is adequate for most typical problems. However, if convergence is slow, the value can be reduced, typically to :math:`0.2` or :math:`0.1`. If divergence is obtained, the value can be increased, typically to :math:`2.0`, :math:`5.0` or :math:`10.0`. **itmax** : int The maximum number of iterations to be used by the function in seeking the solution. A reasonable value might be :math:`20` for a problem with :math:`3000` nodes and convergence criteria of about :math:`10^{-3}` of the original residual and change. **itcoun** : int On the first call of ``dim3_ellip_fd``, :math:`\mathrm{itcoun}` must be set to :math:`0`. On subsequent entries, its value must be unchanged from the previous call. **ndir** : int Indicates whether or not the system of equations has a unique solution. For systems which have a unique solution, :math:`\mathrm{ndir}` must be set to any nonzero value. For systems derived from problems to which an arbitrary constant can be added to the solution, for example Poisson's equation with all Neumann boundary conditions, :math:`\mathrm{ndir}` should be set to :math:`0` and the values of the next three arguments must be specified. For such problems the function subtracts the value of the function derived at the node (:math:`\mathrm{ixn}`, :math:`\mathrm{iyn}`, :math:`\mathrm{izn}`) from the whole solution after each iteration to reduce the possibility of large rounding errors. You must also ensure for such problems that the appropriate compatibility condition on the source terms :math:`\mathrm{q}` is satisfied. See the comments at the end of :ref:`Notes <d03ec-py2-py-notes>`. **ixn** : int Is ignored unless :math:`\mathrm{ndir}` is equal to zero, in which case it must specify the first index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest. **iyn** : int Is ignored unless :math:`\mathrm{ndir}` is equal to zero, in which case it must specify the second index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest. **izn** : int Is ignored unless :math:`\mathrm{ndir}` is equal to zero, in which case it must specify the third index of the nodal point at which the solution is to be set to zero. The node should not correspond to a corner node, or to a node external to the region of interest. **conres** : float The convergence criterion to be used on the maximum absolute value of the normalized residual vector components. The latter is defined as the residual of the algebraic equation divided by the central coefficient when the latter is not equal to :math:`0.0`, and defined as the residual when the central coefficient is zero. :math:`\mathrm{conres}` should not be less than a reasonable multiple of the machine precision. **conchn** : float The convergence criterion to be used on the maximum absolute value of the change made at each iteration to the elements of the array :math:`\mathrm{t}`, namely the dependent variable. :math:`\mathrm{conchn}` should not be less than a reasonable multiple of the machine accuracy multiplied by the maximum value of :math:`\mathrm{t}` attained. Convergence is achieved when both the convergence criteria are satisfied. You can, therefore, set convergence on either the residual or on the change, or (as is recommended) on a requirement that both are below prescribed limits. **Returns** **t** : float, ndarray, shape :math:`\left(\textit{n1}, \mathrm{n2}, \textit{n3}\right)` The solution derived by the function. **itcoun** : int Its value is increased by the number of iterations used on this call (namely :math:`\mathrm{itused}`). It, therefore, stores the accumulated number of iterations actually used. For subsequent calls for the same problem, i.e., with the same :math:`\textit{n1}`, :math:`\mathrm{n2}` and :math:`\textit{n3}` but possibly different coefficients and/or source terms, as occur with nonlinear systems or with time-dependent systems, :math:`\mathrm{itcoun}` should not be reset, i.e., it must contain the accumulated number of iterations. In this way a suitable cycling of the sequence of iteration arguments is obtained in the calls to :meth:`dim3_ellip_fd_iter`. **itused** : int The number of iterations actually used on that call. **resids** : float, ndarray, shape :math:`\left(\mathrm{itmax}\right)` The maximum absolute value of the residuals calculated at the :math:`\textit{i}`\ th iteration, for :math:`\textit{i} = 1,2,\ldots,\mathrm{itused}`. If the residual of the solution is sought you must calculate this in the function from which ``dim3_ellip_fd`` is called. The sequence of values :math:`\mathrm{resids}` indicates the rate of convergence. **chngs** : float, ndarray, shape :math:`\left(\mathrm{itmax}\right)` The maximum absolute value of the changes made to the components of the dependent variable :math:`\mathrm{t}` at the :math:`\textit{i}`\ th iteration, for :math:`\textit{i} = 1,2,\ldots,\mathrm{itused}`. The sequence of values :math:`\mathrm{chngs}` indicates the rate of convergence. .. _d03ec-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\textit{n3} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{n3} > 1`. (`errno` :math:`1`) On entry, :math:`\mathrm{n2} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{n2} > 1`. (`errno` :math:`1`) On entry, :math:`\textit{n1} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{n1} > 1`. (`errno` :math:`2`) On entry, :math:`\textit{sda} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{n2} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{sda}\geq \mathrm{n2}`. (`errno` :math:`3`) On entry, :math:`\mathrm{aparam} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{aparam} > 0.0`. (`errno` :math:`4`) On entry, :math:`\mathrm{aparam} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{n1} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{n2} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{n3} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{aparam}\leq \left(\left(\textit{n1}-1\right)^2+\left(\mathrm{n2}-1\right)^2+\left(\textit{n3}-1\right)^2\right)/3`. (`errno` :math:`5`) Convergence not achieved in :math:`\mathrm{itmax}` iterations: :math:`\mathrm{itmax} = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03ec-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` Given a set of simultaneous equations .. math:: Mt = q (which could be nonlinear) derived, for example, from a finite difference representation of a three-dimensional elliptic partial differential equation and its boundary conditions, the function determines the values of the dependent variable :math:`t`. :math:`M` is a square :math:`\left(n_1\times n_2\times n_3\right)` by :math:`\left(n_1\times n_2\times n_3\right)` matrix and :math:`q` is a known vector of length :math:`\left(n_1\times n_2\times n_3\right)`. The equations must be of seven-diagonal form: .. math:: a_{{ijk}}t_{{ij,k-1}}+b_{{ijk}}t_{{i,j-1,k}}+c_{{ijk}}t_{{i-1,jk}}+d_{{ijk}}t_{{ijk}}+e_{{ijk}}t_{{i+1,jk}}+f_{{ijk}}t_{{i,j+1,k}}+g_{{ijk}}t_{{ij,k+1}} = q_{{ijk}} for :math:`i = 1,2,\ldots,n_1`, :math:`j = 1,2,\ldots,n_2` and :math:`k = 1,2,\ldots,n_3`, provided that :math:`d_{{ijk}}\neq 0.0`. Indeed, if :math:`d_{{ijk}} = 0.0`, then the equation is assumed to be: .. math:: t_{{ijk}} = q_{{ijk}}\text{.} The system is solved iteratively from a starting approximation :math:`t^{\left(1\right)}` by the formulae: .. math:: \begin{array}{lll}r^{\left(n\right)}& = &q-Mt^{\left(n\right)}\\Ms^{\left(n\right)}& = &r^{\left(n\right)}\\t^{\left(n+1\right)}& = &t^{\left(n\right)}+s^{\left(n\right)}\text{.}\end{array} Thus :math:`r^{\left(n\right)}` is the residual of the :math:`n`\ th approximate solution :math:`t^{\left(n\right)}`, and :math:`s^{\left(n\right)}` is the update change vector. The calling program supplies an initial approximation for the values of the dependent variable in the array :math:`\mathrm{t}`, the coefficients of the seven-point molecule system of equations in the arrays :math:`\mathrm{a}`, :math:`\mathrm{b}`, :math:`\mathrm{c}`, :math:`\mathrm{d}`, :math:`\mathrm{e}`, :math:`\mathrm{f}` and :math:`\mathrm{g}`, and the source terms in the array :math:`\mathrm{q}`. The function derives the residual of the latest approximate solution, and then uses the approximate :math:`LU` factorization of the Strongly Implicit Procedure with the necessary acceleration argument adjustment by calling :meth:`dim3_ellip_fd_iter` at each iteration. ``dim3_ellip_fd`` combines the newly derived change with the old approximation to obtain the new approximate solution for :math:`t`. The new solution is checked for convergence against the user-supplied convergence criteria, and if these have not been satisfied, the iterative cycle is repeated. Convergence is based on both the maximum absolute normalized residuals (calculated with reference to the previous approximate solution as these are calculated at the commencement of each iteration) and on the maximum absolute change made to the values of :math:`t`. Problems in topologically non-rectangular-box-shaped regions can be solved using the function by surrounding the region by a circumscribing topologically rectangular box. The equations for the nodal values external to the region of interest are set to zero (i.e., :math:`d_{{ijk}} = t_{{ijk}} = 0`) and the boundary conditions are incorporated into the equations for the appropriate nodes. If there is no better initial approximation when starting the iterative cycle, one can use an array of zeros as the initial approximation. The function can be used to solve linear elliptic equations in which case the arrays :math:`\mathrm{a}`, :math:`\mathrm{b}`, :math:`\mathrm{c}`, :math:`\mathrm{d}`, :math:`\mathrm{e}`, :math:`\mathrm{f}`, :math:`\mathrm{g}` and :math:`\mathrm{q}` remain constant and for which a single call provides the required solution. It can also be used to solve nonlinear elliptic equations, in which case some or all of these arrays may require updating during the progress of the iterations as more accurate solutions are derived. The function will then have to be called repeatedly in an outer iterative cycle. Dependent on the nonlinearity, some under-relaxation of the coefficients and/or source terms may be needed during their recalculation using the new estimates of the solution. The function can also be used to solve each step of a time-dependent parabolic equation in three space dimensions. The solution at each time step can be expressed in terms of an elliptic equation if the Crank--Nicolson or other form of implicit time integration is used. Neither diagonal dominance, nor positive-definiteness, of the matrix :math:`M` formed from the arrays :math:`\mathrm{a}`, :math:`\mathrm{b}`, :math:`\mathrm{c}`, :math:`\mathrm{d}`, :math:`\mathrm{e}`, :math:`\mathrm{f}` and :math:`\mathrm{g}` is necessary to ensure convergence. For problems in which the solution is not unique in the sense that an arbitrary constant can be added to the solution (for example Poisson's equation with all Neumann boundary conditions), an argument is incorporated so that the solution can be rescaled. A specified nodal value is subtracted from the whole solution :math:`t` after the completion of every iteration. This keeps rounding errors to a minimum for those cases when convergence is slow. For such problems there is generally an associated compatibility condition. For the example mentioned this compatibility condition equates the total net source within the region (i.e., the source integrated over the region) with the total net outflow across the boundaries defined by the Neumann conditions (i.e., the normal derivative integrated along the whole boundary). It is very important that the algebraic equations derived to model such a problem implement accurately the compatibility condition. If they do not, a net source or sink is very likely to be represented by the set of algebraic equations and no steady-state solution of the equations exists. .. _d03ec-py2-py-references: **References** Jacobs, D A H, 1972, `The strongly implicit procedure for the numerical solution of parabolic and elliptic partial differential equations`, Note RD/L/N66/72, Central Electricity Research Laboratory Stone, H L, 1968, `Iterative solution of implicit approximations of multi-dimensional partial differential equations`, SIAM J. Numer. Anal. (5), 530--558 Weinstein, H G, Stone, H L and Kwan, T V, 1969, `Iterative procedure for solution of systems of parabolic and elliptic equations in three dimensions`, Industrial and Engineering Chemistry Fundamentals (8), 281--287 """ raise NotImplementedError
[docs]def dim2_ellip_mgrid(ngx, ngy, a, rhs, ub, maxit, acc, iout, io_manager=None): r""" ``dim2_ellip_mgrid`` solves seven-diagonal systems of linear equations which arise from the discretization of an elliptic partial differential equation on a rectangular region. This function uses a multigrid technique. .. _d03ed-py2-py-doc: For full information please refer to the NAG Library document for d03ed https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03edf.html .. _d03ed-py2-py-parameters: **Parameters** **ngx** : int The number of interior grid points in the :math:`x`-direction, :math:`n_x`. :math:`\mathrm{ngx}-1` should preferably be divisible by as high a power of :math:`2` as possible. **ngy** : int The number of interior grid points in the :math:`y`-direction, :math:`n_y`. :math:`\mathrm{ngy}-1` should preferably be divisible by as high a power of :math:`2` as possible. **a** : float, array-like, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3, 7\right)` :math:`\mathrm{a}[{\textit{i}+\left(\textit{j}-1\right)\times \mathrm{ngx}}-1,\textit{k}-1]` must be set to :math:`\mathrm{a}_{{\textit{i}\textit{j}}}^{\textit{k}}`, for :math:`\textit{k} = 1,2,\ldots,7`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{ngy}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngx}`. **rhs** : float, array-like, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3\right)` :math:`\mathrm{rhs}[\textit{i}+\left(\textit{j}-1\right)\times \mathrm{ngx}-1]` must be set to :math:`f_{{\textit{i}\textit{j}}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{ngy}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngx}`. **ub** : float, array-like, shape :math:`\left(\mathrm{ngx}\times \mathrm{ngy}\right)` :math:`\mathrm{ub}[i+\left(j-1\right)\times \mathrm{ngx}-1]` must be set to the initial estimate for the solution :math:`u_{{ij}}`. **maxit** : int The maximum permitted number of multigrid iterations. If :math:`\mathrm{maxit} = 0`, no multigrid iterations are performed, but the coarse-grid approximations and incomplete Crout decompositions are computed, and may be output if :math:`\mathrm{iout}` is set accordingly. **acc** : float The required tolerance for convergence of the residual :math:`2`-norm: .. math:: \left\lVert r\right\rVert_2 = \sqrt{\sum_{{k = 1}}^{{\mathrm{ngx}\times \mathrm{ngy}}}\left(r_k\right)^2} where :math:`r = f-Au` and :math:`u` is the computed solution. Note that the norm is not scaled by the number of equations. The function will stop after fewer than :math:`\mathrm{maxit}` iterations if the residual :math:`2`-norm is less than the specified tolerance. (If :math:`\mathrm{maxit} > 0`, at least one iteration is always performed.) If on entry :math:`\mathrm{acc} = 0.0`, the machine precision is used as a default value for the tolerance; if :math:`\mathrm{acc} > 0.0`, but :math:`\mathrm{acc}` is less than the machine precision, the function will stop when the residual :math:`2`-norm is less than the machine precision and :math:`\textit{errno}` will be set to :math:`4`. **iout** : int Controls the output of printed information to the file object associated with the advisory I/O unit (see :class:`~naginterfaces.base.utils.FileObjManager`): :math:`\mathrm{iout} = 0` No output. :math:`\mathrm{iout} = 1` The solution :math:`u_{{\textit{i}\textit{j}}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{ngy}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngx}`. :math:`\mathrm{iout} = 2` The residual :math:`2`-norm after each iteration, with the reduction factor over the previous iteration. :math:`\mathrm{iout} = 3` As for :math:`\mathrm{iout} = 1` and :math:`\mathrm{iout} = 2`. :math:`\mathrm{iout} = 4` As for :math:`\mathrm{iout} = 3`, plus the final residual (as returned in :math:`\mathrm{ub}`). :math:`\mathrm{iout} = 5` As for :math:`\mathrm{iout} = 4`, plus the initial elements of :math:`\mathrm{a}` and :math:`\mathrm{rhs}`. :math:`\mathrm{iout} = 6` As for :math:`\mathrm{iout} = 5`, plus the Galerkin coarse grid approximations. :math:`\mathrm{iout} = 7` As for :math:`\mathrm{iout} = 6`, plus the incomplete Crout decompositions. :math:`\mathrm{iout} = 8` As for :math:`\mathrm{iout} = 7`, plus the residual after each iteration. The elements :math:`\mathrm{a}[p-1,k-1]`, the Galerkin coarse grid approximations and the incomplete Crout decompositions are output in the format: Y-index :math:`\text{} = j` X-index :math:`\text{} = i\mathrm{a}[p-1,0]\mathrm{a}[p-1,1]\mathrm{a}[p-1,2]\mathrm{a}[p-1,3]\mathrm{a}[p-1,4]\mathrm{a}[p-1,5]\mathrm{a}[p-1,6]` where :math:`p = \textit{i}+\left(\textit{j}-1\right)\times \mathrm{ngx}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{ngy}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngx}`. The vectors :math:`\mathrm{u}[p-1]`, :math:`\mathrm{ub}[p-1]`, :math:`\mathrm{rhs}[p-1]` are output in matrix form with :math:`\mathrm{ngy}` rows and :math:`\mathrm{ngx}` columns. Where :math:`\mathrm{ngx} > 10`, the :math:`\mathrm{ngx}` values for a given :math:`j` value are produced in rows of :math:`10`. Values of :math:`\mathrm{iout} > 4` may yield considerable amounts of output. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **Returns** **a** : float, ndarray, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3, 7\right)` Is overwritten. **rhs** : float, ndarray, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3\right)` The first :math:`\mathrm{ngx}\times \mathrm{ngy}` elements are unchanged and the rest of the array is used as workspace. **ub** : float, ndarray, shape :math:`\left(\mathrm{ngx}\times \mathrm{ngy}\right)` The corresponding component of the residual :math:`r = f-\mathrm{a}u`. **us** : float, ndarray, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3\right)` The residual :math:`2`-norm, stored in element :math:`\mathrm{us}[0]`. **u** : float, ndarray, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3\right)` The computed solution :math:`u_{{\textit{i}\textit{j}}}` is returned in :math:`\mathrm{u}[\textit{i}+\left(\textit{j}-1\right)\times \mathrm{ngx}-1]`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{ngy}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngx}`. **numit** : int The number of iterations performed. .. _d03ed-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{maxit} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{maxit}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{acc}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{iout} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`0\leq \mathrm{iout}\leq 8`. (`errno` :math:`1`) On entry, :math:`\mathrm{ngy} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ngy} \geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{ngx} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ngx} \geq 3`. (`errno` :math:`3`) After :math:`\mathrm{maxit}` iterations the residual norm is not less than the tolerance :math:`\mathrm{maxit} = \langle\mathit{\boldsymbol{value}}\rangle`, residual norm :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`, tolerance :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`. The residual norm increased at one or more iterations after the first. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) After :math:`\mathrm{maxit}` iterations the residual norm is not less than the tolerance :math:`\mathrm{maxit} = \langle\mathit{\boldsymbol{value}}\rangle`, residual norm :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`, tolerance :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`. The residual norm has decreased at each iteration after the first. (`errno` :math:`4`) On entry, :math:`\mathrm{acc}` is less than machine precision. The function terminated because the residual norm is less than machine precision. residual norm :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`, machine precision :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03ed-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_ellip_mgrid`` solves, by multigrid iteration, the seven-point scheme .. math:: \begin{array}{clclcl}&A_{{i,j}}^6u_{{i-1,j+1}}&+&A_{{i,j}}^7u_{{i,j+1}}&&\\+&A_{{i,j}}^3u_{{i-1,j}}&+&A_{{i,j}}^4u_{{ij}}&+&A_{{i,j}}^5u_{{i+1,j}}\\&&+&A_{{i,j}}^1u_{{i,j-1}}&+&A_{{i,j}}^2u_{{i+1,j-1}} = f_{{ij}}\text{, }\quad i = 1,2,\ldots,n_x\text{ and }j = 1,2,\ldots,n_y\text{,}\end{array} which arises from the discretization of an elliptic partial differential equation of the form .. math:: \alpha \left(x, y\right)U_{{xx}}+\beta \left(x, y\right)U_{{xy}}+\gamma \left(x, y\right)U_{{yy}}+\delta \left(x, y\right)U_x+\epsilon \left(x, y\right)U_y+\phi \left(x, y\right)U = \psi \left(x, y\right) and its boundary conditions, defined on a rectangular region. This we write in matrix form as .. math:: Au = f\text{.} The algorithm is described in separate reports by Wesseling (1982a), Wesseling (1982b) and McCarthy (1983). Systems of linear equations, matching the seven-point stencil defined above, are solved by a multigrid iteration. An initial estimate of the solution must be provided by you. A zero guess may be supplied if no better approximation is available. A 'smoother' based on incomplete Crout decomposition is used to eliminate the high frequency components of the error. A restriction operator is then used to map the system on to a sequence of coarser grids. The errors are then smoothed and prolongated (mapped onto successively finer grids). When the finest cycle is reached, the approximation to the solution is corrected. The cycle is repeated for :math:`\mathrm{maxit}` iterations or until the required accuracy, :math:`\mathrm{acc}`, is reached. ``dim2_ellip_mgrid`` will automatically determine the number :math:`l` of possible coarse grids, 'levels' of the multigrid scheme, for a particular problem. In other words, ``dim2_ellip_mgrid`` determines the maximum integer :math:`l` so that :math:`n_x` and :math:`n_y` can be expressed in the form .. math:: n_x = m2^{{l-1}}+1\text{, }\quad n_y = n2^{{l-1}}+1\text{, with }\quad m\geq 2\text{ and }n\geq 2\text{.} It should be noted that the rate of convergence improves significantly with the number of levels used (see McCarthy (1983)), so that :math:`n_x` and :math:`n_y` should be carefully chosen so that :math:`n_x-1` and :math:`n_y-1` have factors of the form :math:`2^l`, with :math:`l` as large as possible. For good convergence the integer :math:`l` should be at least :math:`2`. ``dim2_ellip_mgrid`` has been found to be robust in application, but being an iterative method the problem of divergence can arise. For a strictly diagonally dominant matrix :math:`A` .. math:: \left\lvert A_{{ij}}^4\right\rvert > \sum_{{k\neq 4}}\left\lvert A_{{ij}}^k\right\rvert \text{, }\quad i = 1,2,\ldots,n_x\text{ and }j = 1,2,\ldots,n_y no such problem is foreseen. The diagonal dominance of :math:`A` is not a necessary condition, but should this condition be strongly violated then divergence may occur. The quickest test is to try the function. .. _d03ed-py2-py-references: **References** McCarthy, G J, 1983, `Investigation into the multigrid code MGD1`, Report AERE-R 10889, Harwell Wesseling, P, 1982, `MGD1 -- a robust and efficient multigrid method`, Multigrid Methods. Lecture Notes in Mathematics (960), 614--630, Springer--Verlag Wesseling, P, 1982, `Theoretical aspects of a multigrid method`, SIAM J. Sci. Statist. Comput. (3), 387--407 """ raise NotImplementedError
[docs]def dim2_ellip_discret(xmin, xmax, ymin, ymax, pdef, bndy, ngx, ngy, scheme, data=None): r""" ``dim2_ellip_discret`` discretizes a second-order elliptic partial differential equation (PDE) on a rectangular region. .. _d03ee-py2-py-doc: For full information please refer to the NAG Library document for d03ee https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03eef.html .. _d03ee-py2-py-parameters: **Parameters** **xmin** : float The lower and upper :math:`x` coordinates of the rectangular region respectively, :math:`x_A` and :math:`x_B`. **xmax** : float The lower and upper :math:`x` coordinates of the rectangular region respectively, :math:`x_A` and :math:`x_B`. **ymin** : float The lower and upper :math:`y` coordinates of the rectangular region respectively, :math:`y_A` and :math:`y_B`. **ymax** : float The lower and upper :math:`y` coordinates of the rectangular region respectively, :math:`y_A` and :math:`y_B`. **pdef** : callable (alpha, beta, gamma, delta, epslon, phi, psi) = pdef(x, y, data=None) :math:`\mathrm{pdef}` must evaluate the functions :math:`\alpha \left(x, y\right)`, :math:`\beta \left(x, y\right)`, :math:`\gamma \left(x, y\right)`, :math:`\delta \left(x, y\right)`, :math:`\epsilon \left(x, y\right)`, :math:`\phi \left(x, y\right)` and :math:`\psi \left(x, y\right)` which define the equation at a general point :math:`\left(x, y\right)`. **Parameters** **x** : float The :math:`x` and :math:`y` coordinates of the point at which the coefficients of the partial differential equation are to be evaluated. **y** : float The :math:`x` and :math:`y` coordinates of the point at which the coefficients of the partial differential equation are to be evaluated. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **alpha** : float :math:`\mathrm{alpha}` must be set to the value of :math:`\textit{alpha}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **beta** : float :math:`\mathrm{beta}` must be set to the value of :math:`\textit{beta}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **gamma** : float :math:`\mathrm{gamma}` must be set to the value of :math:`\textit{gamma}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **delta** : float :math:`\mathrm{delta}` must be set to the value of :math:`\textit{delta}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **epslon** : float :math:`\mathrm{epslon}` must be set to the value of :math:`\textit{epislon}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **phi** : float :math:`\mathrm{phi}` must be set to the value of :math:`\textit{phi}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **psi** : float :math:`\mathrm{psi}` must be set to the value of :math:`\textit{psi}(\mathrm{x},\mathrm{y})` at the point specified by :math:`\mathrm{x}` and :math:`\mathrm{y}`. **bndy** : callable (a, b, c) = bndy(x, y, ibnd, data=None) :math:`\mathrm{bndy}` must evaluate the functions :math:`a\left(x, y\right)`, :math:`b\left(x, y\right)`, and :math:`c\left(x, y\right)` involved in the boundary conditions. **Parameters** **x** : float The :math:`x` and :math:`y` coordinates of the point at which the boundary conditions are to be evaluated. **y** : float The :math:`x` and :math:`y` coordinates of the point at which the boundary conditions are to be evaluated. **ibnd** : int Specifies on which boundary the point :math:`\left(\mathrm{x}, \mathrm{y}\right)` lies. :math:`\mathrm{ibnd} = 0`, :math:`1`, :math:`2` or :math:`3` according as the point lies on the bottom, right, top or left boundary. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **a** : float :math:`\mathrm{a}`, :math:`\mathrm{b}` and :math:`\mathrm{c}` must be set to the values of the functions appearing in the boundary conditions. **b** : float :math:`\mathrm{a}`, :math:`\mathrm{b}` and :math:`\mathrm{c}` must be set to the values of the functions appearing in the boundary conditions. **c** : float :math:`\mathrm{a}`, :math:`\mathrm{b}` and :math:`\mathrm{c}` must be set to the values of the functions appearing in the boundary conditions. **ngx** : int The number of interior grid points in the :math:`x`- and :math:`y`-directions respectively, :math:`n_x` and :math:`n_y`. If the seven-diagonal equations are to be solved by :meth:`dim2_ellip_mgrid`, :math:`\mathrm{ngx}-1` and :math:`\mathrm{ngy}-1` should preferably be divisible by as high a power of :math:`2` as possible. **ngy** : int The number of interior grid points in the :math:`x`- and :math:`y`-directions respectively, :math:`n_x` and :math:`n_y`. If the seven-diagonal equations are to be solved by :meth:`dim2_ellip_mgrid`, :math:`\mathrm{ngx}-1` and :math:`\mathrm{ngy}-1` should preferably be divisible by as high a power of :math:`2` as possible. **scheme** : str, length 1 The type of approximation to be used for the first derivatives which occur in the partial differential equation. :math:`\mathrm{scheme} = \texttt{'C'}` Central differences are used. :math:`\mathrm{scheme} = \texttt{'U'}` Upwind differences are used. **data** : arbitrary, optional User-communication data for callback functions. **Returns** **a** : float, ndarray, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3, 7\right)` :math:`\mathrm{a}[\textit{i}-1,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,7`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngx}\times \mathrm{ngy}`, contains the seven-diagonal linear equations produced by the discretization described above. If :math:`\textit{lda} > \mathrm{ngx}\times \mathrm{ngy}`, the remaining elements are not referenced by the function, but if :math:`\textit{lda}\geq \left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3` then the array :math:`\mathrm{a}` can be passed directly to :meth:`dim2_ellip_mgrid`, where these elements are used as workspace. **rhs** : float, ndarray, shape :math:`\left(\left(4\times \left(\mathrm{ngx}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3\right)` The first :math:`\mathrm{ngx}\times \mathrm{ngy}` elements contain the right-hand sides of the seven-diagonal linear equations produced by the discretization described above. If :math:`\textit{lda} > \mathrm{ngx}\times \mathrm{ngy}`, the remaining elements are not referenced by the function, but if :math:`\textit{lda}\geq \left(4\times \left(\mathrm{ngy}+1\right)\times \left(\mathrm{ngy}+1\right)\right)/3` then the array :math:`\mathrm{rhs}` can be passed directly to :meth:`dim2_ellip_mgrid`, where these elements are used as workspace. .. _d03ee-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{scheme} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{scheme} = \texttt{'C'}` or :math:`\texttt{'U'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ngy} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ngy} \geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{ngx} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ngx} \geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{ngx}\times \mathrm{ngy} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{lda} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{lda}` must be at least :math:`\mathrm{ngx}\times \mathrm{ngy}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ymin} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ymax} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ymin} < \mathrm{ymax}`. (`errno` :math:`1`) On entry, :math:`\mathrm{xmin} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xmax} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xmin} < \mathrm{xmax}`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at top left boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at top right boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at bottom left boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at bottom right boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at right boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at left boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at top boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`2`) Mixed derivative in equation and derivative in boundary condition at bottom boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at left boundary, top end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at top boundary, left end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at right boundary, top end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at top boundary, right end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at left boundary, bottom end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at bottom boundary, left end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at right boundary, bottom end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at bottom boundary, right end. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at right boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at left boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at top boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. (`errno` :math:`3`) Null boundary condition at bottom boundary. :math:`\left(x, y\right) = \left(\langle\mathit{\boldsymbol{value}}\rangle\text{, }\langle\mathit{\boldsymbol{value}}\rangle\right)`. **Warns** **NagAlgorithmicWarning** (`errno` :math:`4`) Equation not elliptic at some point. (`errno` :math:`5`) There is no unique solution with Neumann Boundary conditions. (`errno` :math:`6`) The linear equations were not diagonally dominant. .. _d03ee-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_ellip_discret`` discretizes a second-order linear elliptic partial differential equation of the form .. math:: \alpha \left(x, y\right)\frac{{\partial^2U}}{{\partial x^2}}+\beta \left(x, y\right)\frac{{\partial^2U}}{{{\partial x}{\partial y}}}+\gamma \left(x, y\right)\frac{{\partial^2U}}{{\partial y^2}}+\delta \left(x, y\right)\frac{{\partial U}}{{\partial x}}+\epsilon \left(x, y\right)\frac{{\partial U}}{{\partial y}}+\phi \left(x, y\right)U = \psi \left(x, y\right) on a rectangular region .. math:: \begin{array}{c}x_A\leq x\leq x_B\\y_A\leq y\leq y_B\end{array} subject to boundary conditions of the form .. math:: a\left(x, y\right)U+b\left(x, y\right)\frac{{\partial U}}{{\partial n}} = c\left(x, y\right) where :math:`\frac{{\partial U}}{{\partial n}}` denotes the outward pointing normal derivative on the boundary. Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03eef.html#eqn1>`__ is said to be elliptic if .. math:: 4\alpha \left(x, y\right)\gamma \left(x, y\right)\geq \left(\beta \left(x, y\right)\right)^2 for all points in the rectangular region. The linear equations produced are in a form suitable for passing directly to the multigrid function :meth:`dim2_ellip_mgrid`. The equation is discretized on a rectangular grid, with :math:`n_x` grid points in the :math:`x`-direction and :math:`n_y` grid points in the :math:`y`-direction. The grid spacing used is, therefore, .. math:: \begin{array}{c}h_x = \left(x_B-x_A\right)/\left(n_x-1\right)\\h_y = \left(y_B-y_A\right)/\left(n_y-1\right)\end{array} and the coordinates of the grid points :math:`\left(x_i, y_j\right)` are .. math:: \begin{array}{c}x_i = x_A+\left(i-1\right)h_x\text{, }\quad i = 1,2,\ldots,n_x\text{,}\\y_j = y_A+\left(j-1\right)h_y\text{, }\quad j = 1,2,\ldots,n_y\text{.}\end{array} At each grid point :math:`\left(x_i, y_j\right)` 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 [label omitted]. [figure omitted] For convenience the approximation :math:`u_{{ij}}` to the exact solution :math:`U\left(x_i, y_j\right)` is denoted by :math:`u_{\mathrm{O}}`, 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: .. math:: \begin{array}{lll} \frac{{\partial^2U}}{{\partial x^2}}&\simeq &\frac{1}{{h_x^2}}\left(u_{\mathrm{E}}-2u_{\mathrm{O}}+u_{\mathrm{W}}\right)\\ \frac{{\partial^2U}}{{\partial y^2}}&\simeq &\frac{1}{{h_y^2}}\left(u_{\mathrm{N}}-2u_{\mathrm{O}}+u_{\mathrm{S}}\right)\\ \frac{{\partial^2U}}{{\partial x\partial y}}&\simeq &\frac{1}{{2h_xh_y}}\left(u_{\mathrm{N}}-u_{\mathrm{NW}}+u_{\mathrm{E}}-2u_{\mathrm{O}}+u_{\mathrm{W}}-u_{\mathrm{SE}}+u_{\mathrm{S}}\right)\text{.}\end{array} Two possible schemes may be used to approximate the first derivatives: Central Differences .. math:: \begin{array}{lll}\frac{{\partial U}}{{\partial x}}&\simeq &\frac{1}{{2h_x}}\left(u_{\mathrm{E}}-u_{\mathrm{W}}\right)\\\frac{{\partial U}}{{\partial y}}&\simeq &\frac{1}{{2h_y}}\left(u_{\mathrm{N}}-u_{\mathrm{S}}\right)\end{array} Upwind Differences .. math:: \begin{array}{llll}\frac{{\partial U}}{{\partial x}}&\simeq &\frac{1}{h_x}\left(u_{\mathrm{O}}-u_{\mathrm{W}}\right)&\text{if }\quad \delta \left(x, y\right) > 0\\\frac{{\partial U}}{{\partial x}}&\simeq &\frac{1}{h_x}\left(u_{\mathrm{E}}-u_{\mathrm{O}}\right)&\text{if }\quad \delta \left(x, y\right) < 0\\\frac{{\partial U}}{{\partial y}}&\simeq &\frac{1}{h_y}\left(u_{\mathrm{N}}-u_{\mathrm{O}}\right)&\text{if }\quad \epsilon \left(x, y\right) > 0\\\frac{{\partial U}}{{\partial y}}&\simeq &\frac{1}{h_y}\left(u_{\mathrm{O}}-u_{\mathrm{S}}\right)&\text{if }\quad \epsilon \left(x, y\right) < 0\text{.}\end{array} 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: .. math:: \begin{array}{lll}\frac{{\partial U}}{{\partial x}}&\simeq &\frac{1}{{2h_x}} \left(\left(k_x-1\right)u_{\mathrm{W}}-2k_xu_{\mathrm{O}}+\left(k_x+1\right)u_{\mathrm{E}}\right) \\\frac{{\partial U}}{{\partial y}}&\simeq &\frac{1}{{2h_y}} \left(\left(k_y-1\right)u_{\mathrm{S}}-2k_yu_{\mathrm{O}}+\left(k_y+1\right)u_{\mathrm{N}}\right) \end{array} where :math:`k_x = \mathrm{sign}\left(\delta \right)` and :math:`k_y = \mathrm{sign}\left(\epsilon \right)` for upwind differences, and :math:`k_x = k_y = 0` for central differences. At all points in the rectangular domain, including the boundary, the coefficients in the partial differential equation are evaluated by calling :math:`\mathrm{pdef}`, and applying the approximations. This leads to a seven-diagonal system of linear equations of the form: .. math:: \begin{array}{lllllll}&&A_{{ij}}^6u_{{i-1,j+1}}&+&A_{{ij}}^7u_{{i,j+1}}&&\\&+&A_{{ij}}^3u_{{i-1,j}}&+&A_{{ij}}^4u_{{ij}}&+&A_{{ij}}^5u_{{i+1,j}}\\&&&+&A_{{ij}}^1u_{{i,j-1}}&+&A_{{ij}}^2u_{{i+1,j-1}} = f_{{ij}}\text{, }\quad i = 1,2,\ldots,n_x\text{ and }j = 1,2,\ldots,n_y\text{,}\end{array} where the coefficients are given by .. math:: \begin{array}{lll}A_{{ij}}^1& = &\beta \left(x_i, y_j\right)\frac{1}{{2h_xh_y}}+\gamma \left(x_i, y_j\right)\frac{1}{{h_y^2}}+\epsilon \left(x_i, y_j\right)\frac{1}{{2h_y}}\left(k_y-1\right)\\A_{{ij}}^2& = &-\beta \left(x_i, y_j\right)\frac{1}{{2h_xh_y}}\\A_{{ij}}^3& = &\alpha \left(x_i, y_j\right)\frac{1}{{h_x^2}}+\beta \left(x_i, y_j\right)\frac{1}{{2h_xh_y}}+\delta \left(x_i, y_j\right)\frac{1}{{2h_x}}\left(k_x-1\right)\\A_{{ij}}^4& = &-\alpha \left(x_i, y_j\right)\frac{2}{{h_x^2}}-\beta \left(x_i, y_j\right)\frac{1}{{h_xh_y}}-\gamma \left(x_i, y_j\right)\frac{2}{{h_y^2}}-\delta \left(x_i, y_j\right)\frac{k_y}{h_x}-\epsilon \left(x_i, y_j\right)\frac{k_y}{h_y}-\phi \left(x_i, y_j\right)\\A_{{ij}}^5& = &\alpha \left(x_i, y_j\right)\frac{1}{{h_x^2}}+\beta \left(x_i, y_j\right)\frac{1}{{2h_xh_y}}+\delta \left(x_i, y_j\right)\frac{1}{{2h_x}}\left(k_x+1\right)\\A_{{ij}}^6& = &-\beta \left(x_i, y_j\right)\frac{1}{{2h_xh_y}}\\A_{{ij}}^7& = &\beta \left(x_i, y_j\right)\frac{1}{{2h_xh_y}}+\gamma \left(x_i, y_j\right)\frac{1}{{h_y^2}}+\epsilon \left(x_i, y_j\right)\frac{1}{{2h_y}}\left(k_y+1\right)\\f_{{ij}}& = &\psi \left(x_i, y_j\right)\end{array} 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: .. math:: \mu u_{{ij}} = \mu f_{{ij}},\mu \neq 0\text{.} If :meth:`dim2_ellip_mgrid` is used to solve the discretized equations, it turns out that the choice of :math:`\mu` can have a dramatic effect on the rate of convergence, and the obvious choice :math:`\mu = 1` 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: .. math:: \mu = \mathrm{min}_{{ij}}\left(-\left\{\frac{2}{{h_x^2}}+\frac{2}{{h_y^2}}\right\},A_{{ij}}^4\right)\text{.} If the boundary conditions are either mixed or Neumann (i.e., :math:`B\neq 0` on return from :math:`\mathrm{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, :math:`u_{\text{outside}}`: .. math:: \frac{{\partial U}}{{\partial n}}\simeq \frac{1}{{2h}}\left(u_{\mathrm{outside}}-u_{\mathrm{inside}}\right)\text{.} It should be noted that if the boundary conditions are Neumann and :math:`\phi \left(x, y\right)\equiv 0`, then there is no unique solution. The function returns with :math:`\mathrm{errno}` = 5 in this case, and the seven-diagonal matrix is singular. The four corners are treated separately. :math:`\mathrm{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) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03eef.html#eqn2>`__. 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) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03eef.html#eqn3>`__. 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 function calls :math:`\mathrm{pdef}` at **all** points in the domain, including boundary points, arithmetic errors may occur in :math:`\mathrm{pdef}` which this function cannot trap. If you have an equation with Dirichlet boundary conditions (i.e., :math:`B = 0` at all points on the boundary), but with PDE coefficients which are singular on the boundary, then :meth:`dim2_ellip_mgrid` 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, .. math:: \left\lvert A_{{ij}}^4\right\rvert > \sum_{{k\neq 4}}\left\lvert A_{{ij}}^k\right\rvert \text{, }\quad i = 1,2,\ldots,n_x\text{ and }j = 1,2,\ldots,n_y\text{.} If this condition is not satisfied then the function returns with :math:`\mathrm{errno}` = 6. The multigrid function:meth:`dim2_ellip_mgrid` 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 (:math:`\mathrm{scheme} = \texttt{'U'}`). Since this function is designed primarily for use with :meth:`dim2_ellip_mgrid`, this document should be read in conjunction with the document for that function. .. _d03ee-py2-py-references: **References** Wesseling, P, 1982, `MGD1 -- a robust and efficient multigrid method`, Multigrid Methods. Lecture Notes in Mathematics (960), 614--630, Springer--Verlag """ raise NotImplementedError
[docs]def dim3_ellip_helmholtz(xs, xf, l, lbdcnd, bdxs, bdxf, ys, yf, mbdcnd, bdys, bdyf, zs, zf, nbdcnd, bdzs, bdzf, lamda, f): r""" ``dim3_ellip_helmholtz`` solves the Helmholtz equation in Cartesian coordinates in three dimensions using the standard seven-point finite difference approximation. This function is designed to be particularly efficient on vector processors. .. _d03fa-py2-py-doc: For full information please refer to the NAG Library document for d03fa https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03faf.html .. _d03fa-py2-py-parameters: **Parameters** **xs** : float The lower bound of the range of :math:`x`, i.e., :math:`\mathrm{xs}\leq x\leq \mathrm{xf}`. **xf** : float The upper bound of the range of :math:`x`, i.e., :math:`\mathrm{xs}\leq x\leq \mathrm{xf}`. **l** : int The number of panels into which the interval :math:`\left(\mathrm{xs}, \mathrm{xf}\right)` is subdivided. Hence, there will be :math:`\mathrm{l}+1` grid points in the :math:`x`-direction given by :math:`x_{\textit{i}} = \mathrm{xs}+\left(\textit{i}-1\right)\times \delta x`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{l}+1`, where :math:`\delta x = \left(\mathrm{xf}-\mathrm{xs}\right)/\mathrm{l}` is the panel width. **lbdcnd** : int Indicates the type of boundary conditions at :math:`x = \mathrm{xs}` and :math:`x = \mathrm{xf}`. :math:`\mathrm{lbdcnd} = 0` If the solution is periodic in :math:`x`, i.e., :math:`u\left(\mathrm{xs}, y, z\right) = u\left(\mathrm{xf}, y, z\right)`. :math:`\mathrm{lbdcnd} = 1` If the solution is specified at :math:`x = \mathrm{xs}` and :math:`x = \mathrm{xf}`. :math:`\mathrm{lbdcnd} = 2` If the solution is specified at :math:`x = \mathrm{xs}` and the derivative of the solution with respect to :math:`x` is specified at :math:`x = \mathrm{xf}`. :math:`\mathrm{lbdcnd} = 3` If the derivative of the solution with respect to :math:`x` is specified at :math:`x = \mathrm{xs}` and :math:`x = \mathrm{xf}`. :math:`\mathrm{lbdcnd} = 4` If the derivative of the solution with respect to :math:`x` is specified at :math:`x = \mathrm{xs}` and the solution is specified at :math:`x = \mathrm{xf}`. **bdxs** : float, array-like, shape :math:`\left(m+1, n+1\right)` The values of the derivative of the solution with respect to :math:`x` at :math:`x = \mathrm{xs}`. When :math:`\mathrm{lbdcnd} = 3` or :math:`4`, :math:`\mathrm{bdxs}[\textit{j}-1,\textit{k}-1] = u_x\left(\mathrm{xs}, y_j, z_k\right)`, for :math:`\textit{k} = 1,2,\ldots,n+1`, for :math:`\textit{j} = 1,2,\ldots,m+1`. When :math:`\mathrm{lbdcnd}` has any other value, :math:`\mathrm{bdxs}` is not referenced. **bdxf** : float, array-like, shape :math:`\left(m+1, n+1\right)` The values of the derivative of the solution with respect to :math:`x` at :math:`x = \mathrm{xf}`. When :math:`\mathrm{lbdcnd} = 2` or :math:`3`, :math:`\mathrm{bdxf}[\textit{j}-1,\textit{k}-1] = u_x\left(\mathrm{xf}, y_{\textit{j}}, z_{\textit{k}}\right)`, for :math:`\textit{k} = 1,2,\ldots,n+1`, for :math:`\textit{j} = 1,2,\ldots,m+1`. When :math:`\mathrm{lbdcnd}` has any other value, :math:`\mathrm{bdxf}` is not referenced. **ys** : float The lower bound of the range of :math:`y`, i.e., :math:`\mathrm{ys}\leq y\leq \mathrm{yf}`. **yf** : float The upper bound of the range of :math:`y`, i.e., :math:`\mathrm{ys}\leq y\leq \mathrm{yf}`. **mbdcnd** : int Indicates the type of boundary conditions at :math:`y = \mathrm{ys}` and :math:`y = \mathrm{yf}`. :math:`\mathrm{mbdcnd} = 0` If the solution is periodic in :math:`y`, i.e., :math:`u\left(x, \mathrm{yf}, z\right) = u\left(x, \mathrm{ys}, z\right)`. :math:`\mathrm{mbdcnd} = 1` If the solution is specified at :math:`y = \mathrm{ys}` and :math:`y = \mathrm{yf}`. :math:`\mathrm{mbdcnd} = 2` If the solution is specified at :math:`y = \mathrm{ys}` and the derivative of the solution with respect to :math:`y` is specified at :math:`y = \mathrm{yf}`. :math:`\mathrm{mbdcnd} = 3` If the derivative of the solution with respect to :math:`y` is specified at :math:`y = \mathrm{ys}` and :math:`y = \mathrm{yf}`. :math:`\mathrm{mbdcnd} = 4` If the derivative of the solution with respect to :math:`y` is specified at :math:`y = \mathrm{ys}` and the solution is specified at :math:`y = \mathrm{yf}`. **bdys** : float, array-like, shape :math:`\left(\mathrm{l}+1, n+1\right)` The values of the derivative of the solution with respect to :math:`y` at :math:`y = \mathrm{ys}`. When :math:`\mathrm{mbdcnd} = 3` or :math:`4`, :math:`\mathrm{bdys}[\textit{i}-1,\textit{k}-1] = u_y\left(x_{\textit{i}}, \mathrm{ys}, z_{\textit{k}}\right)`, for :math:`\textit{k} = 1,2,\ldots,n+1`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{l}+1`. When :math:`\mathrm{mbdcnd}` has any other value, :math:`\mathrm{bdys}` is not referenced. **bdyf** : float, array-like, shape :math:`\left(\mathrm{l}+1, n+1\right)` The values of the derivative of the solution with respect to :math:`y` at :math:`y = \mathrm{yf}`. When :math:`\mathrm{mbdcnd} = 2` or :math:`3`, :math:`\mathrm{bdyf}[\textit{i}-1,\textit{k}-1] = u_y\left(x_{\textit{i}}, \mathrm{yf}, z_{\textit{k}}\right)`, for :math:`\textit{k} = 1,2,\ldots,n+1`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{l}+1`. When :math:`\mathrm{mbdcnd}` has any other value, :math:`\mathrm{bdyf}` is not referenced. **zs** : float The lower bound of the range of :math:`z`, i.e., :math:`\mathrm{zs}\leq z\leq \mathrm{zf}`. **zf** : float The upper bound of the range of :math:`z`, i.e., :math:`\mathrm{zs}\leq z\leq \mathrm{zf}`. **nbdcnd** : int Specifies the type of boundary conditions at :math:`z = \mathrm{zs}` and :math:`z = \mathrm{zf}`. :math:`\mathrm{nbdcnd} = 0` if the solution is periodic in :math:`z`, i.e., :math:`u\left(x, y, \mathrm{zf}\right) = u\left(x, y, \mathrm{zs}\right)`. :math:`\mathrm{nbdcnd} = 1` if the solution is specified at :math:`z = \mathrm{zs}` and :math:`z = \mathrm{zf}`. :math:`\mathrm{nbdcnd} = 2` if the solution is specified at :math:`z = \mathrm{zs}` and the derivative of the solution with respect to :math:`z` is specified at :math:`z = \mathrm{zf}`. :math:`\mathrm{nbdcnd} = 3` if the derivative of the solution with respect to :math:`z` is specified at :math:`z = \mathrm{zs}` and :math:`z = \mathrm{zf}`. :math:`\mathrm{nbdcnd} = 4` if the derivative of the solution with respect to :math:`z` is specified at :math:`z = \mathrm{zs}` and the solution is specified at :math:`z = \mathrm{zf}`. **bdzs** : float, array-like, shape :math:`\left(\mathrm{l}+1, m+1\right)` The values of the derivative of the solution with respect to :math:`z` at :math:`z = \mathrm{zs}`. When :math:`\mathrm{nbdcnd} = 3` or :math:`4`, :math:`\mathrm{bdzs}[\textit{i}-1,\textit{j}-1] = u_z\left(x_i, y_j, \mathrm{zs}\right)`, for :math:`\textit{j} = 1,2,\ldots,m+1`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{l}+1`. When :math:`\mathrm{nbdcnd}` has any other value, :math:`\mathrm{bdzs}` is not referenced. **bdzf** : float, array-like, shape :math:`\left(\mathrm{l}+1, m+1\right)` The values of the derivative of the solution with respect to :math:`z` at :math:`z = \mathrm{zf}`. When :math:`\mathrm{nbdcnd} = 2` or :math:`3`, :math:`\mathrm{bdzf}[\textit{i}-1,\textit{j}-1] = u_z\left(x_i, y_j, \mathrm{zf}\right)`, for :math:`\textit{j} = 1,2,\ldots,m+1`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{l}+1`. When :math:`\mathrm{nbdcnd}` has any other value, :math:`\mathrm{bdzf}` is not referenced. **lamda** : float The constant :math:`\lambda` in the Helmholtz equation. For certain positive values of :math:`\lambda` a solution to the differential equation may not exist, and close to these values the solution of the discretized problem will be extremely ill-conditioned. If :math:`\lambda > 0`, ``dim3_ellip_helmholtz`` will set :math:`\mathrm{errno}` = 3, but will still attempt to find a solution. However, since in general the values of :math:`\lambda` for which no solution exists cannot be predicted `a priori`, you are advised to treat any results computed with :math:`\lambda > 0` with great caution. **f** : float, array-like, shape :math:`\left(\mathrm{l}+1, m+1, n+1\right)` The values of the right-side of the Helmholtz equation and boundary values (if any). .. math:: \mathrm{f}[i-1,j-1,k-1] = f\left(x_i, y_j, z_k\right)\quad \text{ }\quad i = 2,3,\ldots,\mathrm{l},j = 2,3,\ldots,m\text{ and }k = 2,3,\ldots,n\text{.} On the boundaries :math:`\mathrm{f}` is defined by +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |:math:`\mathrm{lbdcnd}`|:math:`\mathrm{f}[0,j-1,k-1]` |:math:`\mathrm{f}[\mathrm{l},j-1,k-1]` | | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |0 |:math:`f\left(\mathrm{xs}, y_j, z_k\right)`|:math:`f\left(\mathrm{xs}, y_j, z_k\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |1 |:math:`u\left(\mathrm{xs}, y_j, z_k\right)`|:math:`u\left(\mathrm{xf}, y_j, z_k\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |2 |:math:`u\left(\mathrm{xs}, y_j, z_k\right)`|:math:`f\left(\mathrm{xf}, y_j, z_k\right)`|:math:`j = 1,2,\ldots,m+1` | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |3 |:math:`f\left(\mathrm{xs}, y_j, z_k\right)`|:math:`f\left(\mathrm{xf}, y_j, z_k\right)`|:math:`k = 1,2,\ldots,n+1` | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |4 |:math:`f\left(\mathrm{xs}, y_j, z_k\right)`|:math:`u\left(\mathrm{xf}, y_j, z_k\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ | | | | | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |:math:`\mathrm{mbdcnd}`|:math:`\mathrm{f}[i-1,0,k-1]` |:math:`\mathrm{f}[i-1,m,k-1]` | | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |0 |:math:`f\left(x_i, \mathrm{ys}, z_k\right)`|:math:`f\left(x_i, \mathrm{ys}, z_k\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |1 |:math:`u\left(x_i, \mathrm{ys}, z_k\right)`|:math:`u\left(x_i, \mathrm{yf}, z_k\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |2 |:math:`u\left(x_i, \mathrm{ys}, z_k\right)`|:math:`f\left(x_i, \mathrm{yf}, z_k\right)`|:math:`i = 1,2,\ldots,\mathrm{l}+1`| +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |3 |:math:`f\left(x_i, \mathrm{ys}, z_k\right)`|:math:`f\left(x_i, \mathrm{yf}, z_k\right)`|:math:`k = 1,2,\ldots,n+1` | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |4 |:math:`f\left(x_i, \mathrm{ys}, z_k\right)`|:math:`u\left(x_i, \mathrm{yf}, z_k\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ | | | | | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |:math:`\mathrm{nbdcnd}`|:math:`\mathrm{f}[i-1,j-1,0]` |:math:`\mathrm{f}[i-1,j-1,n]` | | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |0 |:math:`f\left(x_i, y_j, \mathrm{zs}\right)`|:math:`f\left(x_i, y_j, \mathrm{zs}\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |1 |:math:`u\left(x_i, y_j, \mathrm{zs}\right)`|:math:`u\left(x_i, y_j, \mathrm{zf}\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |2 |:math:`u\left(x_i, y_j, \mathrm{zs}\right)`|:math:`f\left(x_i, y_j, \mathrm{zf}\right)`|:math:`i = 1,2,\ldots,\mathrm{l}+1`| +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |3 |:math:`f\left(x_i, y_j, \mathrm{zs}\right)`|:math:`f\left(x_i, y_j, \mathrm{zf}\right)`|:math:`j = 1,2,\ldots,m+1` | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ |4 |:math:`f\left(x_i, y_j, \mathrm{zs}\right)`|:math:`u\left(x_i, y_j, \mathrm{zf}\right)`| | +-----------------------+-------------------------------------------+-------------------------------------------+-----------------------------------+ Note: if the table calls for both the solution :math:`u` and the right-hand side :math:`f` on a boundary, the solution must be specified. **Returns** **f** : float, ndarray, shape :math:`\left(\mathrm{l}+1, m+1, n+1\right)` Contains the solution :math:`u\left(\textit{i}, \textit{j}, \textit{k}\right)` of the finite difference approximation for the grid point :math:`\left(x_{\textit{i}}, y_{\textit{j}}, z_{\textit{k}}\right)`, for :math:`\textit{k} = 1,2,\ldots,n+1`, for :math:`\textit{j} = 1,2,\ldots,m+1`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{l}+1`. **pertrb** : float :math:`\mathrm{pertrb} = 0`, unless a solution to Poisson's equation :math:`\left(\lambda = 0\right)` is required with a combination of periodic or derivative boundary conditions (:math:`\mathrm{lbdcnd}`, :math:`\mathrm{mbdcnd}` and :math:`\mathrm{nbdcnd} = 0` or :math:`3`). In this case a solution may not exist. :math:`\mathrm{pertrb}` is a constant, calculated and subtracted from the array :math:`\mathrm{f}`, which ensures that a solution exists. ``dim3_ellip_helmholtz`` then computes this solution, which is a least squares solution to the original approximation. This solution is not unique and is unnormalized. The value of :math:`\mathrm{pertrb}` should be small compared to the right-hand side :math:`\mathrm{f}`, otherwise a solution has been obtained to an essentially different problem. This comparison should always be made to ensure that a meaningful solution has been obtained. .. _d03fa-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{nbdcnd} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nbdcnd} \geq 0` and :math:`\mathrm{nbdcnd} \leq 4`. (`errno` :math:`1`) On entry, :math:`n = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`n \geq 5`. (`errno` :math:`1`) On entry, :math:`\mathrm{zs} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{zf} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{zs} < \mathrm{zf}`. (`errno` :math:`1`) On entry, :math:`\mathrm{mbdcnd} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{mbdcnd} \geq 0` and :math:`\mathrm{mbdcnd} \leq 4`. (`errno` :math:`1`) On entry, :math:`m = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`m \geq 5`. (`errno` :math:`1`) On entry, :math:`\mathrm{ys} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{yf} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ys} < \mathrm{yf}` (`errno` :math:`1`) On entry, :math:`\mathrm{lbdcnd} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{lbdcnd} \geq 0` and :math:`\mathrm{lbdcnd} \leq 4`. (`errno` :math:`1`) On entry, :math:`\mathrm{l} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{l} \geq 5`. (`errno` :math:`1`) On entry, :math:`\mathrm{xs} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xf} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xs} < \mathrm{xf}`. **Warns** **NagAlgorithmicWarning** (`errno` :math:`3`) :math:`\lambda > 0.0` in Helmholtz's equation -- a solution may not exist. .. _d03fa-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim3_ellip_helmholtz`` solves the three-dimensional Helmholtz equation in Cartesian coordinates: .. math:: \frac{{\partial^2u}}{{\partial x^2}}+\frac{{\partial^2u}}{{\partial y^2}}+\frac{{\partial^2u}}{{\partial z^2}}+\lambda u = f\left(x, y, z\right)\text{.} This function forms the system of linear equations resulting from the standard seven-point finite difference equations, and then solves the system using a method based on the fast Fourier transform (FFT) described by Swarztrauber (1984). This function is based on the function HW3CRT from FISHPACK (see Swarztrauber and Sweet (1979)). More precisely, the function replaces all the second derivatives by second-order central difference approximations, resulting in a block tridiagonal system of linear equations. The equations are modified to allow for the prescribed boundary conditions. Either the solution or the derivative of the solution may be specified on any of the boundaries, or the solution may be specified to be periodic in any of the three dimensions. By taking the discrete Fourier transform in the :math:`x`- and :math:`y`-directions, the equations are reduced to sets of tridiagonal systems of equations. The Fourier transforms required are computed using the multiple FFT functions found in submodule :mod:`~naginterfaces.library.sum`. .. _d03fa-py2-py-references: **References** Swarztrauber, P N, 1984, `Fast Poisson solvers`, Studies in Numerical Analysis, (ed G H Golub), Mathematical Association of America Swarztrauber, P N and Sweet, R A, 1979, `Efficient Fortran subprograms for the solution of separable elliptic partial differential equations`, ACM Trans. Math. Software (5), 352--364 """ raise NotImplementedError
[docs]def dim2_triangulate(h, m, n, nb, sdindx, isin, data=None): r""" ``dim2_triangulate`` places a triangular mesh over a given two-dimensional region. The region may have any shape, including one with holes. .. _d03ma-py2-py-doc: For full information please refer to the NAG Library document for d03ma https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03maf.html .. _d03ma-py2-py-parameters: **Parameters** **h** : float :math:`h`, the required length for the sides of the triangles of the uniform mesh. **m** : int The value :math:`m` such that all points inside the region satisfy the documented inequalities. **n** : int The value :math:`n` such that all points inside the region satisfy the documented inequalities. **nb** : int The number of times a triangle side is bisected to find a point on the boundary. A value of :math:`10` is adequate for most purposes (see `Accuracy <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03maf.html#accuracy>`__). **sdindx** : int The second dimension of the arrays :math:`\mathrm{places}` and :math:`\mathrm{indx}`. **isin** : callable retval = isin(x, y, data=None) :math:`\mathrm{isin}` must return the value :math:`1` if the given point :math:`\left(\mathrm{x}, \mathrm{y}\right)` lies inside the region, and :math:`0` if it lies outside. **Parameters** **x** : float The coordinates of the given point. **y** : float The coordinates of the given point. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **retval** : int The value :math:`1` if the given point :math:`\left(\mathrm{x}, \mathrm{y}\right)` lies inside the region, and :math:`0` if it lies outside. **data** : arbitrary, optional User-communication data for callback functions. **Returns** **npts** : int The number of points in the triangulation. **places** : float, ndarray, shape :math:`\left(2, \mathrm{npts}\right)` The :math:`x` and :math:`y` coordinates respectively of the :math:`i`\ th point of the triangulation. **indx** : int, ndarray, shape :math:`\left(4, \mathrm{npts}\right)` :math:`\mathrm{indx}[0,i-1]` contains :math:`i` if point :math:`i` is inside the region and :math:`{-i}` if it is on the boundary. For each triangle side between points :math:`i` and :math:`j` with :math:`j > i`, :math:`\mathrm{indx}[k-1,i-1]`, :math:`k > 1`, contains :math:`j` or :math:`{-j}` according to whether point :math:`j` is internal or on the boundary. There can never be more than three such points. If there are less, some values :math:`\mathrm{indx}[k-1,i-1]`, :math:`k > 1`, are zero. .. _d03ma-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) :math:`\mathrm{sdindx}` is too small: :math:`\mathrm{sdindx} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) A point inside the region violates one of the constraints. (`errno` :math:`4`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} > 2`. (`errno` :math:`5`) On entry, :math:`\mathrm{n} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{n} > 2`. (`errno` :math:`6`) On entry, :math:`\mathrm{nb} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nb} > 0`. .. _d03ma-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_triangulate`` begins with a uniform triangular grid as shown in Figure [label omitted] and assumes that the region to be triangulated lies within the rectangle given by the inequalities .. math:: 0 < x < \sqrt{3}\left(m-1\right)h\text{, }\quad 0 < y < \left(n-1\right)h\text{.} This rectangle is drawn in bold in Figure [label omitted]. The region is specified by the :math:`\mathrm{isin}` which must determine whether any given point :math:`\left(x, y\right)` lies in the region. The uniform grid is processed column-wise, with :math:`\left(x_1, y_1\right)` preceding :math:`\left(x_2, y_2\right)` if :math:`x_1 < x_2` or :math:`x_1 = x_2`, :math:`y_1 < y_2`. Points near the boundary are moved onto it and points well outside the boundary are omitted. The direction of movement is chosen to avoid pathologically thin triangles. The points accepted are numbered in exactly the same order as the corresponding points of the uniform grid were scanned. The output consists of the :math:`x,y` coordinates of all grid points and integers indicating whether they are internal and to which other points they are joined by triangle sides. The mesh size :math:`h` must be chosen small enough for the essential features of the region to be apparent from testing all points of the original uniform grid for being inside the region. For instance if any hole is within :math:`2h` of another hole or the outer boundary then a triangle may be found with all vertices within :math:`\frac{1}{2}h` of a boundary. Such a triangle is taken to be external to the region so the effect will be to join the hole to another hole or to the external region. Further details of the algorithm are given in the references. [figure omitted] .. _d03ma-py2-py-references: **References** Reid, J K, 1970, `Fortran subroutines for the solutions of Laplace's equation over a general routine in two dimensions`, Harwell Report TP422 Reid, J K, 1972, `On the construction and convergence of a finite-element solution of Laplace's equation`, J. Instr. Math. Appl. (9), 1--13 """ raise NotImplementedError
[docs]def dim1_blackscholes_fd(kopt, x, mesh, s, t, tdpar, r, q, sigma, ntkeep, alpha=0.55): r""" ``dim1_blackscholes_fd`` solves the Black--Scholes equation for financial option pricing using a finite difference scheme. .. _d03nc-py2-py-doc: For full information please refer to the NAG Library document for d03nc https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ncf.html .. _d03nc-py2-py-parameters: **Parameters** **kopt** : int Specifies the kind of option to be valued. :math:`\mathrm{kopt} = 1` A European call option. :math:`\mathrm{kopt} = 2` An American call option. :math:`\mathrm{kopt} = 3` A European put option. :math:`\mathrm{kopt} = 4` An American put option. **x** : float The exercise price :math:`X`. **mesh** : str, length 1 Indicates the type of finite difference mesh to be used: :math:`\mathrm{mesh} = \texttt{'U'}` Uniform mesh. :math:`\mathrm{mesh} = \texttt{'C'}` Custom mesh supplied by you. **s** : float, array-like, shape :math:`\left(\textit{ns}\right)` If :math:`\mathrm{mesh} = \texttt{'C'}`, :math:`\mathrm{s}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th stock price in the mesh, for :math:`\textit{i} = 1,2,\ldots,\textit{ns}`. These values should be in increasing order, with :math:`\mathrm{s}[0] = S_{\mathrm{min}}` and :math:`\mathrm{s}[\textit{ns}-1] = S_{\mathrm{max}}`. If :math:`\mathrm{mesh} = \texttt{'U'}`, :math:`\mathrm{s}[0]` must be set to :math:`S_{\mathrm{min}}` and :math:`\mathrm{s}[\textit{ns}-1]` to :math:`S_{\mathrm{max}}`, but :math:`\mathrm{s}[1],\mathrm{s}[2],\ldots,\mathrm{s}[\textit{ns}-2]` need not be initialized, as they will be set internally by the function in order to define a uniform mesh. **t** : float, array-like, shape :math:`\left(\textit{nt}\right)` If :math:`\mathrm{mesh} = \texttt{'C'}` then :math:`\mathrm{t}[\textit{j}-1]` must contain the :math:`\textit{j}`\ th time in the mesh, for :math:`\textit{j} = 1,2,\ldots,\textit{nt}`. These values should be in increasing order, with :math:`\mathrm{t}[0] = t_{\mathrm{min}}` and :math:`\mathrm{t}[\textit{nt}-1] = t_{\mathrm{max}}`. If :math:`\mathrm{mesh} = \texttt{'U'}` then :math:`\mathrm{t}[0]` must be set to :math:`t_{\mathrm{min}}` and :math:`\mathrm{t}[\textit{nt}-1]` to :math:`t_{\mathrm{max}}`, but :math:`\mathrm{t}[1],\mathrm{t}[2],\ldots,\mathrm{t}[\textit{nt}-2]` need not be initialized, as they will be set internally by the function in order to define a uniform mesh. **tdpar** : bool, array-like, shape :math:`\left(3\right)` Specifies whether or not various arguments are time-dependent. More precisely, :math:`r` is time-dependent if :math:`\mathrm{tdpar}[0] = \mathbf{True}` and constant otherwise. Similarly, :math:`\mathrm{tdpar}[1]` specifies whether :math:`q` is time-dependent and :math:`\mathrm{tdpar}[2]` specifies whether :math:`\sigma` is time-dependent. **r** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{tdpar}[0]= \mathbf{True}`: :math:`\textit{nt}`; otherwise: :math:`1`. If :math:`\mathrm{tdpar}[0] = \mathbf{True}` then :math:`\mathrm{r}[\textit{j}-1]` must contain the value of the risk-free interest rate :math:`r\left(t\right)` at the :math:`\textit{j}`\ th time in the mesh, for :math:`\textit{j} = 1,2,\ldots,\textit{nt}`. If :math:`\mathrm{tdpar}[0] = \mathbf{False}` then :math:`\mathrm{r}[0]` must contain the constant value of the risk-free interest rate :math:`r`. The remaining elements need not be set. **q** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{tdpar}[1]= \mathbf{True}`: :math:`\textit{nt}`; otherwise: :math:`1`. If :math:`\mathrm{tdpar}[1] = \mathbf{True}` then :math:`\mathrm{q}[\textit{j}-1]` must contain the value of the continuous dividend :math:`q\left(t\right)` at the :math:`\textit{j}`\ th time in the mesh, for :math:`\textit{j} = 1,2,\ldots,\textit{nt}`. If :math:`\mathrm{tdpar}[1] = \mathbf{False}` then :math:`\mathrm{q}[0]` must contain the constant value of the continuous dividend :math:`q`. The remaining elements need not be set. **sigma** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{tdpar}[2]= \mathbf{True}`: :math:`\textit{nt}`; otherwise: :math:`1`. If :math:`\mathrm{tdpar}[2] = \mathbf{True}` then :math:`\mathrm{sigma}[\textit{j}-1]` must contain the value of the volatility :math:`\sigma \left(t\right)` at the :math:`\textit{j}`\ th time in the mesh, for :math:`\textit{j} = 1,2,\ldots,\textit{nt}`. If :math:`\mathrm{tdpar}[2] = \mathbf{False}` then :math:`\mathrm{sigma}[0]` must contain the constant value of the volatility :math:`\sigma`. The remaining elements need not be set. **ntkeep** : int The number of solutions to be stored in the time direction. The function calculates the solution backwards from :math:`\mathrm{t}[\textit{nt}-1]` to :math:`\mathrm{t}[0]` at all times in the mesh. These time solutions and the corresponding Greeks will be stored at times :math:`\mathrm{t}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ntkeep}`, in the arrays :math:`\mathrm{f}`, :math:`\mathrm{theta}`, :math:`\mathrm{delta}`, :math:`\mathrm{gamma}`, :math:`\mathrm{lamda}` and :math:`\mathrm{rho}`. Other time solutions will be discarded. To store all time solutions set :math:`\mathrm{ntkeep} = \textit{nt}`. **alpha** : float, optional The value of :math:`\lambda` to be used in the time-stepping scheme. Typical values include: :math:`\mathrm{alpha} = 0.0` Explicit forward Euler scheme. :math:`\mathrm{alpha} = 0.5` Implicit Crank--Nicolson scheme. :math:`\mathrm{alpha} = 1.0` Implicit backward Euler scheme. The value :math:`0.5` gives second-order accuracy in time. Values greater than :math:`0.5` give unconditional stability. Since :math:`0.5` is at the limit of unconditional stability this value does not damp oscillations. **Returns** **s** : float, ndarray, shape :math:`\left(\textit{ns}\right)` If :math:`\mathrm{mesh} = \texttt{'U'}`, the elements of :math:`\mathrm{s}` define a uniform mesh over :math:`\left[S_{\mathrm{min}}, S_{\mathrm{max}}\right]`. If :math:`\mathrm{mesh} = \texttt{'C'}`, the elements of :math:`\mathrm{s}` are unchanged. **t** : float, ndarray, shape :math:`\left(\textit{nt}\right)` If :math:`\mathrm{mesh} = \texttt{'U'}`, the elements of :math:`\mathrm{t}` define a uniform mesh over :math:`\left[t_{\mathrm{min}}, t_{\mathrm{max}}\right]`. If :math:`\mathrm{mesh} = \texttt{'C'}`, the elements of :math:`\mathrm{t}` are unchanged. **f** : float, ndarray, shape :math:`\left(\textit{ns}, \mathrm{ntkeep}\right)` :math:`\mathrm{f}[\textit{i}-1,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{ntkeep}`, for :math:`\textit{i} = 1,2,\ldots,\textit{ns}`, contains the value :math:`f` of the option at the :math:`\textit{i}`\ th mesh point :math:`\mathrm{s}[\textit{i}-1]` at time :math:`\mathrm{t}[\textit{j}-1]`. **theta** : float, ndarray, shape :math:`\left(\textit{ns}, \mathrm{ntkeep}\right)` The values of various Greeks at the :math:`i`\ th mesh point :math:`\mathrm{s}[i-1]` at time :math:`\mathrm{t}[j-1]`, as follows: .. math:: \begin{array}{lll}\mathrm{theta}[i-1,j-1] = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta}[i-1,j-1] = \frac{{\partial f}}{{\partial S}}\text{,}&\mathrm{gamma}[i-1,j-1] = \frac{{\partial^2f}}{{\partial S^2}}\text{,}\\\\\mathrm{lamda}[i-1,j-1] = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho}[i-1,j-1] = \frac{{\partial f}}{{\partial r}}\text{.}\end{array} **delta** : float, ndarray, shape :math:`\left(\textit{ns}, \mathrm{ntkeep}\right)` The values of various Greeks at the :math:`i`\ th mesh point :math:`\mathrm{s}[i-1]` at time :math:`\mathrm{t}[j-1]`, as follows: .. math:: \begin{array}{lll}\mathrm{theta}[i-1,j-1] = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta}[i-1,j-1] = \frac{{\partial f}}{{\partial S}}\text{,}&\mathrm{gamma}[i-1,j-1] = \frac{{\partial^2f}}{{\partial S^2}}\text{,}\\\\\mathrm{lamda}[i-1,j-1] = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho}[i-1,j-1] = \frac{{\partial f}}{{\partial r}}\text{.}\end{array} **gamma** : float, ndarray, shape :math:`\left(\textit{ns}, \mathrm{ntkeep}\right)` The values of various Greeks at the :math:`i`\ th mesh point :math:`\mathrm{s}[i-1]` at time :math:`\mathrm{t}[j-1]`, as follows: .. math:: \begin{array}{lll}\mathrm{theta}[i-1,j-1] = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta}[i-1,j-1] = \frac{{\partial f}}{{\partial S}}\text{,}&\mathrm{gamma}[i-1,j-1] = \frac{{\partial^2f}}{{\partial S^2}}\text{,}\\\\\mathrm{lamda}[i-1,j-1] = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho}[i-1,j-1] = \frac{{\partial f}}{{\partial r}}\text{.}\end{array} **lamda** : float, ndarray, shape :math:`\left(\textit{ns}, \mathrm{ntkeep}\right)` The values of various Greeks at the :math:`i`\ th mesh point :math:`\mathrm{s}[i-1]` at time :math:`\mathrm{t}[j-1]`, as follows: .. math:: \begin{array}{lll}\mathrm{theta}[i-1,j-1] = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta}[i-1,j-1] = \frac{{\partial f}}{{\partial S}}\text{,}&\mathrm{gamma}[i-1,j-1] = \frac{{\partial^2f}}{{\partial S^2}}\text{,}\\\\\mathrm{lamda}[i-1,j-1] = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho}[i-1,j-1] = \frac{{\partial f}}{{\partial r}}\text{.}\end{array} **rho** : float, ndarray, shape :math:`\left(\textit{ns}, \mathrm{ntkeep}\right)` The values of various Greeks at the :math:`i`\ th mesh point :math:`\mathrm{s}[i-1]` at time :math:`\mathrm{t}[j-1]`, as follows: .. math:: \begin{array}{lll}\mathrm{theta}[i-1,j-1] = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta}[i-1,j-1] = \frac{{\partial f}}{{\partial S}}\text{,}&\mathrm{gamma}[i-1,j-1] = \frac{{\partial^2f}}{{\partial S^2}}\text{,}\\\\\mathrm{lamda}[i-1,j-1] = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho}[i-1,j-1] = \frac{{\partial f}}{{\partial r}}\text{.}\end{array} .. _d03nc-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{ntkeep} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ntkeep}\leq \textit{nt}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ntkeep} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ntkeep} \geq 1`. (`errno` :math:`1`) On entry, :math:`\mathrm{alpha} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{alpha}\leq 1.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{alpha} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{alpha}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{mesh} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{mesh} = \texttt{'U'}` or :math:`\texttt{'C'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{t}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{t}[0]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{s}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{s}[0]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{nt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nt} \geq 2`. (`errno` :math:`1`) On entry, :math:`\textit{ns} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{ns} \geq 2`. (`errno` :math:`1`) On entry, :math:`\mathrm{kopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{kopt} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`2`) On entry, :math:`\mathrm{t}[\textit{nt}-1] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{t}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{t}[\textit{nt}-1] > \mathrm{t}[0]`. (`errno` :math:`2`) On entry, :math:`\mathrm{s}[\textit{ns}-1] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{s}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{s}[\textit{ns}-1] > \mathrm{s}[0]`. (`errno` :math:`3`) On entry, :math:`\mathrm{t}[0]\leq \mathrm{t}[\langle\mathit{\boldsymbol{value}}\rangle]`. Constraint: when :math:`\mathrm{mesh} = \texttt{'C'}`, :math:`\mathrm{t}[\textit{i}-1] < \mathrm{t}[\textit{i}]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nt}-1`. (`errno` :math:`3`) On entry, :math:`\mathrm{s}[0]\leq \mathrm{s}[\langle\mathit{\boldsymbol{value}}\rangle]`. Constraint: when :math:`\mathrm{mesh} = \texttt{'C'}`, :math:`\mathrm{s}[\textit{i}-1] < \mathrm{s}[\textit{i}]`, for :math:`\textit{i} = 1,2,\ldots,\textit{ns}-1`. .. _d03nc-py2-py-notes: **Notes** ``dim1_blackscholes_fd`` solves the Black--Scholes equation (see Hull (1989) and Wilmott `et al.` (1995)) .. math:: \frac{{\partial f}}{{\partial t}}+\left(r-q\right)S\frac{{\partial f}}{{\partial S}}+\frac{{\sigma^2S^2}}{2}\frac{{\partial^2f}}{{\partial S^2}} = rf .. math:: S_{\mathrm{min}} < S < S_{\mathrm{max}}\text{, }\quad t_{\mathrm{min}} < t < t_{\mathrm{max}}\text{,} for the value :math:`f` of a European or American, put or call stock option, with exercise price :math:`X`. In equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ncf.html#eqn1>`__ :math:`t` is time, :math:`S` is the stock price, :math:`r` is the risk free interest rate, :math:`q` is the continuous dividend, and :math:`\sigma` is the stock volatility. According to the values in the array :math:`\mathrm{tdpar}`, the arguments :math:`r`, :math:`q` and :math:`\sigma` may each be either constant or functions of time. The function also returns values of various Greeks. ``dim1_blackscholes_fd`` uses a finite difference method with a choice of time-stepping schemes. The method is explicit for :math:`\mathrm{alpha} = 0.0` and implicit for nonzero values of :math:`\mathrm{alpha}`. Second order time accuracy can be obtained by setting :math:`\mathrm{alpha} = 0.5`. According to the value of the argument :math:`\mathrm{mesh}` the finite difference mesh may be either uniform, or user-defined in both :math:`S` and :math:`t` directions. .. _d03nc-py2-py-references: **References** Hull, J, 1989, `Options, Futures and Other Derivative Securities`, Prentice--Hall Wilmott, P, Howison, S and Dewynne, J, 1995, `The Mathematics of Financial Derivatives`, Cambridge University Press """ raise NotImplementedError
[docs]def dim1_blackscholes_closed(kopt, x, s, t, tmat, tdpar, r, q, sigma): r""" ``dim1_blackscholes_closed`` computes an analytic solution to the Black--Scholes equation for a certain set of option types. .. _d03nd-py2-py-doc: For full information please refer to the NAG Library document for d03nd https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ndf.html .. _d03nd-py2-py-parameters: **Parameters** **kopt** : int Specifies the kind of option to be valued: :math:`\mathrm{kopt} = 1` A European call option. :math:`\mathrm{kopt} = 2` An American call option. :math:`\mathrm{kopt} = 3` A European put option. **x** : float The exercise price :math:`X`. **s** : float The stock price at which the option value and the Greeks should be evaluated. **t** : float The time at which the option value and the Greeks should be evaluated. **tmat** : float The maturity time of the option. **tdpar** : bool, array-like, shape :math:`\left(3\right)` Specifies whether or not various arguments are time-dependent. More precisely, :math:`r` is time-dependent if :math:`\mathrm{tdpar}[0] = \mathbf{True}` and constant otherwise. Similarly, :math:`\mathrm{tdpar}[1]` specifies whether :math:`q` is time-dependent and :math:`\mathrm{tdpar}[2]` specifies whether :math:`\sigma` is time-dependent. **r** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{tdpar}[0]= \mathbf{True}`: :math:`3`; otherwise: :math:`1`. If :math:`\mathrm{tdpar}[0] = \mathbf{False}` then :math:`\mathrm{r}[0]` must contain the constant value of :math:`r`. The remaining elements need not be set. If :math:`\mathrm{tdpar}[0] = \mathbf{True}` then :math:`\mathrm{r}[0]` must contain the value of :math:`r` at time :math:`\mathrm{t}` and :math:`\mathrm{r}[1]` must contain its average instantaneous value over the remaining life of the option: .. math:: \hat{r} = \int_\mathrm{t}^{\mathrm{tmat}}r\left(\zeta \right){d\zeta }\text{.} The auxiliary function :meth:`dim1_blackscholes_means` may be used to construct :math:`\mathrm{r}` from a set of values of :math:`r` at discrete times. **q** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{tdpar}[1]= \mathbf{True}`: :math:`3`; otherwise: :math:`1`. If :math:`\mathrm{tdpar}[1] = \mathbf{False}` then :math:`\mathrm{q}[0]` must contain the constant value of :math:`q`. The remaining elements need not be set. If :math:`\mathrm{tdpar}[1] = \mathbf{True}` then :math:`\mathrm{q}[0]` must contain the constant value of :math:`q` and :math:`\mathrm{q}[1]` must contain its average instantaneous value over the remaining life of the option: .. math:: \hat{q} = \int_\mathrm{t}^{\mathrm{tmat}}q\left(\zeta \right){d\zeta }\text{.} The auxiliary function :meth:`dim1_blackscholes_means` may be used to construct :math:`\mathrm{q}` from a set of values of :math:`q` at discrete times. **sigma** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{tdpar}[2]= \mathbf{True}`: :math:`3`; otherwise: :math:`1`. If :math:`\mathrm{tdpar}[2] = \mathbf{False}` then :math:`\mathrm{sigma}[0]` must contain the constant value of :math:`\sigma`. The remaining elements need not be set. If :math:`\mathrm{tdpar}[2] = \mathbf{True}` then :math:`\mathrm{sigma}[0]` must contain the value of :math:`\sigma` at time :math:`\mathrm{t}`, :math:`\mathrm{sigma}[1]` the average instantaneous value :math:`\hat{\sigma }`, and :math:`\mathrm{sigma}[2]` the second-order average :math:`\bar{\sigma }`, where: .. math:: \hat{\sigma } = \int_\mathrm{t}^{\mathrm{tmat}}\sigma \left(\zeta \right){d\zeta }\text{,} .. math:: \bar{\sigma } = \left(\int_\mathrm{t}^{\mathrm{tmat}}\sigma^2\left(\zeta \right){d\zeta }\right)^{{1/2}}\text{.} The auxiliary function :meth:`dim1_blackscholes_means` may be used to compute :math:`\mathrm{sigma}` from a set of values at discrete times. **Returns** **f** : float The value :math:`f` of the option at the stock price :math:`\mathrm{s}` and time :math:`\mathrm{t}`. **theta** : float The values of various Greeks at the stock price :math:`\mathrm{s}` and time :math:`\mathrm{t}`, as follows: .. math:: \begin{array}{lll}\mathrm{theta} = \Theta = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta} = \Delta = \frac{{\partial f}}{{\partial \mathrm{s}}}\text{,}&\mathrm{gamma} = \Gamma = \frac{{\partial^2f}}{{\partial \mathrm{s}^2}} \text{,}\\&&\\\mathrm{lamda} = \Lambda = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho} = \rho = \frac{{\partial f}}{{\partial r}}\text{.}&\end{array} **delta** : float The values of various Greeks at the stock price :math:`\mathrm{s}` and time :math:`\mathrm{t}`, as follows: .. math:: \begin{array}{lll}\mathrm{theta} = \Theta = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta} = \Delta = \frac{{\partial f}}{{\partial \mathrm{s}}}\text{,}&\mathrm{gamma} = \Gamma = \frac{{\partial^2f}}{{\partial \mathrm{s}^2}} \text{,}\\&&\\\mathrm{lamda} = \Lambda = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho} = \rho = \frac{{\partial f}}{{\partial r}}\text{.}&\end{array} **gamma** : float The values of various Greeks at the stock price :math:`\mathrm{s}` and time :math:`\mathrm{t}`, as follows: .. math:: \begin{array}{lll}\mathrm{theta} = \Theta = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta} = \Delta = \frac{{\partial f}}{{\partial \mathrm{s}}}\text{,}&\mathrm{gamma} = \Gamma = \frac{{\partial^2f}}{{\partial \mathrm{s}^2}} \text{,}\\&&\\\mathrm{lamda} = \Lambda = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho} = \rho = \frac{{\partial f}}{{\partial r}}\text{.}&\end{array} **lamda** : float The values of various Greeks at the stock price :math:`\mathrm{s}` and time :math:`\mathrm{t}`, as follows: .. math:: \begin{array}{lll}\mathrm{theta} = \Theta = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta} = \Delta = \frac{{\partial f}}{{\partial \mathrm{s}}}\text{,}&\mathrm{gamma} = \Gamma = \frac{{\partial^2f}}{{\partial \mathrm{s}^2}} \text{,}\\&&\\\mathrm{lamda} = \Lambda = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho} = \rho = \frac{{\partial f}}{{\partial r}}\text{.}&\end{array} **rho** : float The values of various Greeks at the stock price :math:`\mathrm{s}` and time :math:`\mathrm{t}`, as follows: .. math:: \begin{array}{lll}\mathrm{theta} = \Theta = \frac{{\partial f}}{{\partial t}}\text{,}&\mathrm{delta} = \Delta = \frac{{\partial f}}{{\partial \mathrm{s}}}\text{,}&\mathrm{gamma} = \Gamma = \frac{{\partial^2f}}{{\partial \mathrm{s}^2}} \text{,}\\&&\\\mathrm{lamda} = \Lambda = \frac{{\partial f}}{{\partial \sigma }}\text{,}&\mathrm{rho} = \rho = \frac{{\partial f}}{{\partial r}}\text{.}&\end{array} .. _d03nd-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{sigma}[\langle\mathit{\boldsymbol{value}}\rangle] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{sigma}[\textit{i}-1] > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tmat} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{t} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tmat}\geq \mathrm{t}`. (`errno` :math:`1`) On entry, :math:`\mathrm{t} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{t}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{s} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{s}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{x} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{q}[0]` is not equal to :math:`0.0` with American call option. :math:`\mathrm{q}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{kopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{kopt} = 1`, :math:`2` or :math:`3`. .. _d03nd-py2-py-notes: **Notes** ``dim1_blackscholes_closed`` computes an analytic solution to the Black--Scholes equation (see Hull (1989) and Wilmott `et al.` (1995)) .. math:: \frac{{\partial f}}{{\partial t}}+\left(r-q\right)S\frac{{\partial f}}{{\partial S}}+\frac{{\sigma^2S^2}}{2}\frac{{\partial^2f}}{{\partial S^2}} = rf .. math:: S_{\mathrm{min}} < S < S_{\mathrm{max}}\text{, }\quad t_{\mathrm{min}} < t < t_{\mathrm{max}}\text{,} for the value :math:`f` of a European put or call option, or an American call option with zero dividend :math:`q`. In equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ndf.html#eqn1>`__ :math:`t` is time, :math:`S` is the stock price, :math:`X` is the exercise price, :math:`r` is the risk free interest rate, :math:`q` is the continuous dividend, and :math:`\sigma` is the stock volatility. The parameter :math:`r`, :math:`q` and :math:`\sigma` may be either constant, or functions of time. In the latter case their average instantaneous values over the remaining life of the option should be provided to ``dim1_blackscholes_closed``. An auxiliary function :meth:`dim1_blackscholes_means` is available to compute such averages from values at a set of discrete times. Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ndf.html#eqn1>`__ is subject to different boundary conditions depending on the type of option. For a call option the boundary condition is .. math:: f\left(S, {t = t_{\textit{mat}}}\right) = \textit{max}\left(0, {S-X}\right) where :math:`t_{\textit{mat}}` is the maturity time of the option. For a put option the equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ndf.html#eqn1>`__ is subject to .. math:: f\left(S, {t = t_{\textit{mat}}}\right) = \textit{max}\left(0, {X-S}\right)\text{.} ``dim1_blackscholes_closed`` also returns values of the Greeks .. math:: \Theta = \frac{{\partial f}}{{\partial t}}\text{, }\quad \Delta = \frac{{\partial f}}{{\partial x}}\text{, }\quad \Gamma = \frac{{\partial^2f}}{{\partial x^2}}\text{, }\quad \Lambda = \frac{{\partial f}}{{\partial \sigma }}\text{, }\quad \rho = \frac{{\partial f}}{{\partial r}}\text{.} :meth:`specfun.opt_bsm_greeks <naginterfaces.library.specfun.opt_bsm_greeks>` also computes the European option price given by the Black--Scholes--Merton formula together with a more comprehensive set of sensitivities (Greeks). Further details of the analytic solution returned are given in `Algorithmic Details <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ndf.html#algdetails>`__. .. _d03nd-py2-py-references: **References** Hull, J, 1989, `Options, Futures and Other Derivative Securities`, Prentice--Hall Wilmott, P, Howison, S and Dewynne, J, 1995, `The Mathematics of Financial Derivatives`, Cambridge University Press """ raise NotImplementedError
[docs]def dim1_blackscholes_means(t0, tmat, td, phid): r""" ``dim1_blackscholes_means`` computes average values of a continuous function of time over the remaining life of an option. It is used together with :meth:`dim1_blackscholes_closed` to value options with time-dependent arguments. .. _d03ne-py2-py-doc: For full information please refer to the NAG Library document for d03ne https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03nef.html .. _d03ne-py2-py-parameters: **Parameters** **t0** : float The current time :math:`t_0`. **tmat** : float The maturity time :math:`T`. **td** : float, array-like, shape :math:`\left(\textit{ntd}\right)` The discrete times at which :math:`\phi` is specified. **phid** : float, array-like, shape :math:`\left(\textit{ntd}\right)` :math:`\mathrm{phid}[\textit{i}-1]` must contain the value of :math:`\phi` at time :math:`\mathrm{td}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{ntd}`. **Returns** **phiav** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{phiav}[0]` contains the value of :math:`\phi` interpolated to :math:`t_0`, :math:`\mathrm{phiav}[1]` contains the first-order average :math:`\hat{\phi }` and :math:`\mathrm{phiav}[2]` contains the second-order average :math:`\bar{\phi }`, where: .. math:: \begin{array}{cc}\hat{\phi } = \frac{1}{{T-t_0}}\int_{t_0}^T\phi \left(\zeta \right)d\zeta \text{, }\quad &\bar{\phi } = \left(\frac{1}{{T-t_0}}\int_{t_0}^T\phi^2\left(\zeta \right){d\zeta }\right)^{{1/2}}\text{.}\end{array} .. _d03ne-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{td}[0]\leq \mathrm{td}[\langle\mathit{\boldsymbol{value}}\rangle]`. Constraint: :math:`\mathrm{td}[0] < \mathrm{td}[1] < \cdots < \mathrm{td}[\textit{ntd}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{ntd} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{ntd} \geq 2`. (`errno` :math:`1`) On entry, :math:`\mathrm{tmat} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{td}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{td}[\textit{ntd}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{td}[0]\leq \mathrm{tmat}\leq \mathrm{td}[\textit{ntd}-1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{t0} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{td}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{td}[\textit{ntd}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{td}[0]\leq \mathrm{t0}\leq \mathrm{td}[\textit{ntd}-1]`. (`errno` :math:`2`) Unexpected failure in internal call to spline function. .. _d03ne-py2-py-notes: **Notes** ``dim1_blackscholes_means`` computes the quantities .. math:: \begin{array}{ccc}\phi \left(t_0\right)\text{, }\quad &\hat{\phi } = \frac{1}{{T-t_0}}\int_{t_0}^T\phi \left(\zeta \right){d\zeta }\text{, }\quad &\bar{\phi } = \left(\frac{1}{{T-t_0}}\int_{t_0}^T\phi^2\left(\zeta \right){d\zeta }\right)^{{1/2}}\end{array} from a given set of values :math:`\mathrm{phid}` of a continuous time-dependent function :math:`\phi \left(t\right)` at a set of discrete points :math:`\mathrm{td}`, where :math:`t_0` is the current time and :math:`T` is the maturity time. Thus :math:`\hat{\phi }` and :math:`\bar{\phi }` are first and second order averages of :math:`\phi` over the remaining life of an option. The function may be used in conjunction with :meth:`dim1_blackscholes_closed` in order to value an option in the case where the risk-free interest rate :math:`r`, the continuous dividend :math:`q`, or the stock volatility :math:`\sigma` is time-dependent and is described by values at a set of discrete times (see `Use with dim1_blackscholes_closed <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03nef.html#withgbf>`__). """ raise NotImplementedError
[docs]def dim1_parab_fd(m, ts, tout, pdedef, bndary, u, x, acc, comm, itask, itrace, ind, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_fd`` 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. .. _d03pc-py2-py-doc: For full information please refer to the NAG Library document for d03pc https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pcf.html .. _d03pc-py2-py-parameters: **Parameters** **m** : int The coordinate system used: :math:`\mathrm{m} = 0` Indicates Cartesian coordinates. :math:`\mathrm{m} = 1` Indicates cylindrical polar coordinates. :math:`\mathrm{m} = 2` Indicates spherical polar coordinates. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (p, q, r, ires) = pdedef(t, x, u, ux, ires, data=None) :math:`\mathrm{pdedef}` must compute the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which define the system of PDEs. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_fd``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}\right)` :math:`\mathrm{p}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, U_x\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **q** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{q}[\textit{i}-1]` must be set to the value of :math:`Q_{\textit{i}}\left(x, t, U, U_x\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **r** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{r}[\textit{i}-1]` must be set to the value of :math:`R_{\textit{i}}\left(x, t, U, U_x\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (beta, gamma, ires) = bndary(t, u, ux, ibnd, ires, data=None) :math:`\mathrm{bndary}` must compute the functions :math:`\beta_i` and :math:`\gamma_i` which define the boundary conditions as in equation `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pcf.html#eqn3>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ibnd** : int Determines the position of the boundary conditions. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must set up the coefficients of the left-hand boundary, :math:`x = a`. :math:`\mathrm{ibnd} \neq 0` Indicates that :math:`\mathrm{bndary}` must set up the coefficients of the right-hand boundary, :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **beta** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{beta}[\textit{i}-1]` must be set to the value of :math:`\beta_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **gamma** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{gamma}[\textit{i}-1]` must be set to the value of :math:`\gamma_{\textit{i}}\left(x, t, U, U_x\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npts}\right)` The initial values of :math:`U\left(x, t\right)` at :math:`t = \mathrm{ts}` and the mesh points :math:`\mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the spatial direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **acc** : float A positive quantity for controlling the local error estimate in the time integration. If :math:`E\left(i, j\right)` is the estimated error for :math:`U_i` at the :math:`j`\ th mesh point, the error test is: .. math:: \left\lvert E\left(i, j\right)\right\rvert = \mathrm{acc}\times \left(1.0+\left\lvert \mathrm{u}[i-1,j-1]\right\rvert \right)\text{.} **comm** : dict, communication object, modified in place Communication structure. `On initial entry`: need not be set. **itask** : int Specifies the task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 2` One step and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. **itrace** : int The level of trace information required from ``dim1_parab_fd`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_fd``. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{u}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. Two-dimensional arrays returned from callback functions in this routine must then use the same storage order. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` will contain the computed solution at :math:`t = \mathrm{ts}`. **ind** : int :math:`\mathrm{ind} = 1`. .. _d03pc-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{acc} > 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} \leq 0` or :math:`\mathrm{x}[0]\geq 0.0` (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2` or :math:`3`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{acc}` was too small to start integration: :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`14`) Flux function appears to depend on time derivatives. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied value of :math:`\mathrm{acc}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but a small change in :math:`\mathrm{acc}` is unlikely to result in a changed solution. :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pc-py2-py-notes: **Notes** ``dim1_parab_fd`` integrates the system of parabolic equations: .. math:: \sum_{{j = 1}}^{\textit{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+Q_i = x^{{-m}}\frac{\partial }{{\partial x}}\left(x^mR_i\right)\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{, }\quad a\leq x\leq b\text{, }\quad t\geq t_0\text{,} where :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and the vector :math:`U` is the set of solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\textit{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{,} and the vector :math:`U_x` is its partial derivative with respect to :math:`x`. Note that :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` must not depend on :math:`\frac{{\partial U}}{{\partial t}}`. The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}`. The coordinate system in space is defined by the value of :math:`m`; :math:`m = 0` for Cartesian coordinates, :math:`m = 1` for cylindrical polar coordinates and :math:`m = 2` 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 :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which must be specified in :math:`\mathrm{pdedef}`. The initial values of the functions :math:`U\left(x, t\right)` must be given at :math:`t = t_0`. The functions :math:`R_i`, for :math:`\textit{i} = 1,2,\ldots,\textit{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 .. math:: \beta_i\left(x, t\right)R_i\left(x, t, U, U_x\right) = \gamma_i\left(x, t, U, U_x\right)\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{,} where :math:`x = a` or :math:`x = b`. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The problem is subject to the following restrictions: (i) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) :math:`P_{{i,j}}`, :math:`Q_i` and the flux :math:`R_i` must not depend on any time derivatives; (#) the evaluation of the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` is done at the mid-points of the mesh intervals by calling the :math:`\mathrm{pdedef}` for each mid-point in turn. Any discontinuities in these functions **must**, therefore, be at one or more of the mesh points :math:`x_1,x_2,\ldots,x_{\textit{npts}}`; (#) at least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the problem; and (#) if :math:`m > 0` and :math:`x_1 = 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 :math:`x = 0.0` or by specifying a zero flux there, that is :math:`\beta_i = 1.0` and :math:`\gamma_i = 0.0`. See also `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pcf.html#fcomments>`__. The parabolic equations are approximated by a system of ODEs in time for the values of :math:`U_i` 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 :math:`\textit{npde}\times \textit{npts}` ODEs in the time direction. This system is then integrated forwards in time using a backward differentiation formula method. .. _d03pc-py2-py-references: **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 """ raise NotImplementedError
[docs]def dim1_parab_coll(m, ts, tout, pdedef, bndary, u, xbkpts, npoly, uinit, acc, comm, itask, itrace, ind, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_coll`` integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable. The spatial discretization is performed using a Chebyshev :math:`C^0` 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. .. _d03pd-py2-py-doc: For full information please refer to the NAG Library document for d03pd https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pdf.html .. _d03pd-py2-py-parameters: **Parameters** **m** : int The coordinate system used: :math:`\mathrm{m} = 0` Indicates Cartesian coordinates. :math:`\mathrm{m} = 1` Indicates cylindrical polar coordinates. :math:`\mathrm{m} = 2` Indicates spherical polar coordinates. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (p, q, r, ires) = pdedef(t, x, u, ux, ires, data=None) :math:`\mathrm{pdedef}` must compute the values of the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which define the system of PDEs. The functions may depend on :math:`x`, :math:`t`, :math:`U` and :math:`U_x` and must be evaluated at a set of points. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{nptl}\right)` Contains a set of mesh points at which :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` are to be evaluated. :math:`\mathrm{x}[0]` and :math:`\mathrm{x}[\textit{nptl}-1]` contain successive user-supplied break-points and the elements of the array will satisfy :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{nptl}-1]`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{ux}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}, \textit{nptl}\right)` :math:`\mathrm{p}[ \mathrm{npde}\times \mathrm{npde}\times \left(\textit{k}-1\right)+ \mathrm{npde}\times \left(\textit{j}-1\right)+ \left(\textit{i}-1\right)]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, U_x\right)` where :math:`x = \mathrm{x}[\textit{k}-1]`, for :math:`\textit{k} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **q** : float, array-like, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{q}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`Q_{\textit{i}}\left(x, t, U, U_x\right)` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **r** : float, array-like, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{r}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`R_{\textit{i}}\left(x, t, U, U_x\right)` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_coll`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (beta, gamma, ires) = bndary(t, u, ux, ibnd, ires, data=None) :math:`\mathrm{bndary}` must compute the functions :math:`\beta_i` and :math:`\gamma_i` which define the boundary conditions as in equation `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pdf.html#eqn3>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must set up the coefficients of the left-hand boundary, :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must set up the coefficients of the right-hand boundary, :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **beta** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{beta}[\textit{i}-1]` must be set to the value of :math:`\beta_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **gamma** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{gamma}[\textit{i}-1]` must be set to the value of :math:`\gamma_{\textit{i}}\left(x, t, U, U_x\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_coll`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{npde}, \left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1\right)` If :math:`\mathrm{ind} = 1` the value of :math:`\mathrm{u}` must be unchanged from the previous call. **xbkpts** : float, array-like, shape :math:`\left(\textit{nbkpts}\right)` The values of the break-points in the space direction. :math:`\mathrm{xbkpts}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{xbkpts}[\textit{nbkpts}-1]` must specify the right-hand boundary, :math:`b`. **npoly** : int The degree of the Chebyshev polynomial to be used in approximating the PDE solution between each pair of break-points. **uinit** : callable u = uinit(npde, x, data=None) :math:`\mathrm{uinit}` must compute the initial values of the PDE components :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **Parameters** **npde** : int The number of PDEs in the system. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{j}-1]`, contains the values of the :math:`\textit{j}`\ th mesh point, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\mathrm{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` must be set to the initial value :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **acc** : float A positive quantity for controlling the local error estimate in the time integration. If :math:`E\left(i, j\right)` is the estimated error for :math:`U_i` at the :math:`j`\ th mesh point, the error test is: .. math:: \left\lvert E\left(i, j\right)\right\rvert = \mathrm{acc}\times \left(1.0+\left\lvert \mathrm{u}[i-1,j-1]\right\rvert \right)\text{.} **comm** : dict, communication object, modified in place Communication structure. `On initial entry`: need not be set. **itask** : int Specifies the task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 2` One step and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. **itrace** : int The level of trace information required from ``dim1_parab_coll`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_coll``. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{u}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. Two-dimensional arrays returned from callback functions in this routine must then use the same storage order. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1\right)` :math:`\mathrm{u}[i-1,j-1]` will contain the computed solution at :math:`t = \mathrm{ts}`. **x** : float, ndarray, shape :math:`\left(\left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1\right)` The mesh points chosen by ``dim1_parab_coll`` in the spatial direction. The values of :math:`\mathrm{x}` will satisfy :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. **ind** : int :math:`\mathrm{ind} = 1`. .. _d03pd-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xbkpts}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xbkpts}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xbkpts}[0] < \mathrm{xbkpts}[1] < \cdots < \mathrm{xbkpts}[\textit{nbkpts}-1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{acc} > 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{nbkpts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts} = \left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1`. (`errno` :math:`1`) On entry, :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npoly}\leq 49`. (`errno` :math:`1`) On entry, :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npoly}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{nbkpts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nbkpts}\geq 2`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xbkpts}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} \leq 0` or :math:`\mathrm{xbkpts}[0]\geq 0.0` (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2` or :math:`3`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{acc}` was too small to start integration: :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`14`) Flux function appears to depend on time derivatives. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied value of :math:`\mathrm{acc}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but a small change in :math:`\mathrm{acc}` is unlikely to result in a changed solution. :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pd-py2-py-notes: **Notes** ``dim1_parab_coll`` integrates the system of parabolic equations: .. math:: \sum_{{j = 1}}^{\textit{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+Q_i = x^{{-m}}\frac{\partial }{{\partial x}}\left(x^mR_i\right)\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{, }\quad a\leq x\leq b,t\geq t_0\text{,} where :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and the vector :math:`U` is the set of solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\textit{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{,} and the vector :math:`U_x` is its partial derivative with respect to :math:`x`. Note that :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` must not depend on :math:`\frac{{\partial U}}{{\partial t}}`. The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{nbkpts}}` are the leftmost and rightmost of a user-defined set of break-points :math:`x_1,x_2,\ldots,x_{\textit{nbkpts}}`. The coordinate system in space is defined by the value of :math:`m`; :math:`m = 0` for Cartesian coordinates, :math:`m = 1` for cylindrical polar coordinates and :math:`m = 2` for spherical polar coordinates. The system is defined by the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which must be specified in :math:`\mathrm{pdedef}`. The initial values of the functions :math:`U\left(x, t\right)` must be given at :math:`t = t_0`, and must be specified in :math:`\mathrm{uinit}`. The functions :math:`R_i`, for :math:`\textit{i} = 1,2,\ldots,\textit{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 .. math:: \beta_i\left(x, t\right)R_i\left(x, t, U, U_x\right) = \gamma_i\left(x, t, U, U_x\right)\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{,} where :math:`x = a` or :math:`x = b`. The boundary conditions must be specified in :math:`\mathrm{bndary}`. Thus, the problem is subject to the following restrictions: (i) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) :math:`P_{{i,j}}`, :math:`Q_i` and the flux :math:`R_i` must not depend on any time derivatives; (#) the evaluation of the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` is done at both the break-points and internally selected points for each element in turn, that is :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` are evaluated twice at each break-point. Any discontinuities in these functions **must**, therefore, be at one or more of the break-points :math:`x_1,x_2,\ldots,x_{\textit{nbkpts}}`; (#) at least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the problem; (#) if :math:`m > 0` and :math:`x_1 = 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 :math:`x = 0.0` or by specifying a zero flux there, that is :math:`\beta_i = 1.0` and :math:`\gamma_i = 0.0`. See also `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pdf.html#fcomments>`__. The parabolic equations are approximated by a system of ODEs in time for the values of :math:`U_i` 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 :math:`\mathrm{npoly}`. The interval between each pair of break-points is treated by ``dim1_parab_coll`` as an element, and on this element, a polynomial and its space and time derivatives are made to satisfy the system of PDEs at :math:`\mathrm{npoly}-1` spatial points, which are chosen internally by the code and the break-points. In the case of just one element, the break-points are the boundaries. The user-defined break-points and the internally selected points together define the mesh. The smallest value that :math:`\mathrm{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 :math:`\left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1` mesh points in the spatial direction, and :math:`\textit{npde}\times \left(\left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1\right)` ODEs in the time direction; one ODE at each break-point for each PDE component and (:math:`\mathrm{npoly}-1`) ODEs for each PDE component between each pair of break-points. The system is then integrated forwards in time using a backward differentiation formula method. .. _d03pd-py2-py-references: **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) """ raise NotImplementedError
[docs]def dim1_parab_keller(ts, tout, pdedef, bndary, u, x, nleft, acc, comm, itask, itrace, ind, data=None, io_manager=None): r""" ``dim1_parab_keller`` integrates a system of linear or nonlinear, first-order, time-dependent partial differential equations (PDEs) in one space variable. The spatial discretization is performed using the Keller box scheme 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 (BDF) method. .. _d03pe-py2-py-doc: For full information please refer to the NAG Library document for d03pe https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html .. _d03pe-py2-py-parameters: **Parameters** **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (res, ires) = pdedef(t, x, u, ut, ux, ires, data=None) :math:`\mathrm{pdedef}` must compute the functions :math:`G_i` which define the system of PDEs. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_keller``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ut** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial t}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int The form of :math:`G_i` that must be returned in the array :math:`\mathrm{res}`. :math:`\mathrm{ires} = -1` Equation `(8) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn8>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn9>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{res}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`G`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`, where :math:`G` is defined as .. math:: G_{\textit{i}} = \sum_{{\textit{j} = 1}}^{\textit{npde}}P_{{\textit{i},\textit{j}}}\frac{{\partial U_{\textit{j}}}}{{\partial t}}\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: G_{\textit{i}} = \sum_{{\textit{j} = 1}}^{\textit{npde}}P_{{\textit{i},\textit{j}}}\frac{{\partial U_{\textit{j}}}}{{\partial t}}+Q_{\textit{i}}\text{,} i.e., all terms in equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn2>`__. The definition of :math:`G` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: **bndary** : callable (res, ires) = bndary(t, ibnd, nobc, u, ut, ires, data=None) :math:`\mathrm{bndary}` must compute the functions :math:`G_i^L` and :math:`G_i^R` which define the boundary conditions as in equations `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn4>`__ and `(5) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn4>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **ibnd** : int Determines the position of the boundary conditions. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must compute the left-hand boundary condition at :math:`x = a`. :math:`\mathrm{ibnd} \neq 0` Indicates that :math:`\mathrm{bndary}` must compute the right-hand boundary condition at :math:`x = b`. **nobc** : int Specifies the number of boundary conditions at the boundary specified by :math:`\mathrm{ibnd}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ut** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial t}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int The form :math:`G_i^L` (or :math:`G_i^R`) that must be returned in the array :math:`\mathrm{res}`. :math:`\mathrm{ires} = -1` Equation `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn10>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn11>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\mathrm{nobc}\right)` :math:`\mathrm{res}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`G^L` or :math:`G^R`, depending on the value of :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nobc}`, where :math:`G^L` is defined as .. math:: G_{\textit{i}}^L = \sum_{{\textit{j} = 1}}^{\textit{npde}}E_{{\textit{i},\textit{j}}}^L\frac{{\partial U_{\textit{j}}}}{{\partial t}}\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: G_{\textit{i}}^L = \sum_{{\textit{j} = 1}}^{\textit{npde}}E_{{\textit{i},\textit{j}}}^L\frac{{\partial U_{\textit{j}}}}{{\partial t}}+S_{\textit{i}}^L\text{,} i.e., all terms in equation `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pef.html#eqn6>`__, and similarly for :math:`G_{\textit{i}}^R`. The definitions of :math:`G^L` and :math:`G^R` are determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npts}\right)` The initial values of :math:`U\left(x, t\right)` at :math:`t = \mathrm{ts}` and the mesh points :math:`\mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the spatial direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nleft** : int The number :math:`n_a` of boundary conditions at the left-hand mesh point :math:`\mathrm{x}[0]`. **acc** : float A positive quantity for controlling the local error estimate in the time integration. If :math:`E\left(i, j\right)` is the estimated error for :math:`U_i` at the :math:`j`\ th mesh point, the error test is: .. math:: \left\lvert E\left(i, j\right)\right\rvert = \mathrm{acc}\times \left(1.0+\left\lvert \mathrm{u}[i-1,j-1]\right\rvert \right)\text{.} **comm** : dict, communication object, modified in place Communication structure. `On initial entry`: need not be set. **itask** : int Specifies the task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 2` Take one step and return. :math:`\mathrm{itask} = 3` Stop at the first internal integration point at or beyond :math:`t = \mathrm{tout}`. **itrace** : int The level of trace information required from ``dim1_parab_keller`` and the underlying ODE solver as follows: :math:`\mathrm{itrace}\leq -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} = 1` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. :math:`\mathrm{itrace} = 2` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 1`, except that the advisory messages are given in greater detail. :math:`\mathrm{itrace}\geq 3` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 2`, except that the advisory messages are given in greater detail. You are advised to set :math:`\mathrm{itrace} = 0`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_keller``. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` will contain the computed solution at :math:`t = \mathrm{ts}`. **ind** : int :math:`\mathrm{ind} = 1`. .. _d03pe-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{acc} > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nleft} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nleft}\leq \textit{npde}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nleft} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nleft}\geq 0`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2` or :math:`3`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{acc}` was too small to start integration: :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied value of :math:`\mathrm{acc}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but a small change in :math:`\mathrm{acc}` is unlikely to result in a changed solution. :math:`\mathrm{acc} = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pe-py2-py-notes: **Notes** ``dim1_parab_keller`` integrates the system of first-order PDEs .. math:: G_i\left(x, t, U, U_x, U_t\right) = 0\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{.} In particular the functions :math:`G_i` must have the general form .. math:: G_i = \sum_{{j = 1}}^{\textit{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+Q_i\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{, }\quad a\leq x\leq b,t\geq t_0\text{,} where :math:`P_{{i,j}}` and :math:`Q_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and the vector :math:`U` is the set of solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\textit{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{,} and the vector :math:`U_x` is its partial derivative with respect to :math:`x`. Note that :math:`P_{{i,j}}` and :math:`Q_i` must not depend on :math:`\frac{{\partial U}}{{\partial t}}`. The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}`. The mesh should be chosen in accordance with the expected behaviour of the solution. The PDE system which is defined by the functions :math:`G_i` must be specified in :math:`\mathrm{pdedef}`. The initial values of the functions :math:`U\left(x, t\right)` must be given at :math:`t = t_0`. For a first-order system of PDEs, only one boundary condition is required for each PDE component :math:`U_i`. The :math:`\textit{npde}` boundary conditions are separated into :math:`n_a` at the left-hand boundary :math:`x = a`, and :math:`n_b` at the right-hand boundary :math:`x = b`, such that :math:`n_a+n_b = \textit{npde}`. The position of the boundary condition for each component should be chosen with care; the general rule is that if the characteristic direction of :math:`U_i` at the left-hand boundary (say) points into the interior of the solution domain, then the boundary condition for :math:`U_i` should be specified at the left-hand boundary. Incorrect positioning of boundary conditions generally results in initialization or integration difficulties in the underlying time integration functions. The boundary conditions have the form: .. math:: G_i^L\left(x, t, U, U_t\right) = 0\quad \text{ at }x = a\text{, }\quad i = 1,2,\ldots,n_a at the left-hand boundary, and .. math:: G_i^R\left(x, t, U, U_t\right) = 0\quad \text{ at }x = b\text{, }\quad i = 1,2,\ldots,n_b at the right-hand boundary. Note that the functions :math:`G_i^L` and :math:`G_i^R` must not depend on :math:`U_x`, since spatial derivatives are not determined explicitly in the Keller box scheme (see Keller (1970)). If the problem involves derivative (Neumann) boundary conditions then it is generally possible to restate such boundary conditions in terms of permissible variables. Also note that :math:`G_i^L` and :math:`G_i^R` must be linear with respect to time derivatives, so that the boundary conditions have the general form .. math:: \sum_{{j = 1}}^{\textit{npde}}E_{{i,j}}^L\frac{{\partial U_j}}{{\partial t}}+S_i^L = 0\text{, }\quad i = 1,2,\ldots,n_a at the left-hand boundary, and .. math:: \sum_{{j = 1}}^{\textit{npde}}E_{{i,j}}^R\frac{{\partial U_j}}{{\partial t}}+S_i^R = 0\text{, }\quad i = 1,2,\ldots,n_b at the right-hand boundary, where :math:`E_{{i,j}}^L`, :math:`E_{{i,j}}^R`, :math:`S_i^L`, and :math:`S_i^R` depend on :math:`x`, :math:`t` and :math:`U` only. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The problem is subject to the following restrictions: (i) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) :math:`P_{{i,j}}` and :math:`Q_i` must not depend on any time derivatives; (#) The evaluation of the function :math:`G_i` is done at the mid-points of the mesh intervals by calling the :math:`\mathrm{pdedef}` for each mid-point in turn. Any discontinuities in the function **must**, therefore, be at one or more of the mesh points :math:`x_1,x_2,\ldots,x_{\textit{npts}}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the problem. In this method of lines approach the Keller box scheme (see Keller (1970)) is applied to each PDE in the space variable only, resulting in a system of ODEs in time for the values of :math:`U_i` at each mesh point. In total there are :math:`\textit{npde}\times \textit{npts}` ODEs in the time direction. This system is then integrated forwards in time using a BDF method. .. _d03pe-py2-py-references: **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 Keller, H B, 1970, `A new difference scheme for parabolic problems`, Numerical Solutions of Partial Differential Equations, (ed J Bramble) (2), 327--350, Academic Press Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 """ raise NotImplementedError
[docs]def dim1_parab_convdiff(ts, tout, numflx, bndary, u, x, acc, tsmax, comm, itask, itrace, ind, pdedef=None, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_convdiff`` integrates a system of linear or nonlinear convection-diffusion equations in one space dimension, with optional source terms. The system must be posed in conservative form. Convection terms are discretized using a sophisticated upwind scheme involving a user-supplied numerical flux function based on the solution of a Riemann problem at each mesh point. The method of lines is employed to reduce the PDEs to a system of ordinary differential equations (ODEs), and the resulting system is solved using a backward differentiation formula (BDF) method. .. _d03pf-py2-py-doc: For full information please refer to the NAG Library document for d03pf https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html .. _d03pf-py2-py-parameters: **Parameters** **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **numflx** : callable (flux, ires) = numflx(t, x, uleft, uright, ires, data=None) :math:`\mathrm{numflx}` must supply the numerical flux for each PDE given the `left` and `right` values of the solution vector :math:`\mathrm{u}`. :math:`\mathrm{numflx}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_convdiff``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **uleft** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{uleft}[\textit{i}-1]` contains the `left` value of the component :math:`U_{\textit{i}}\left(x\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **uright** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{uright}[\textit{i}-1]` contains the `right` value of the component :math:`U_{\textit{i}}\left(x\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **flux** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{flux}[\textit{i}-1]` must be set to the numerical flux :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (g, ires) = bndary(t, x, u, ibnd, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_i^L` and :math:`G_i^R` which describe the physical and numerical boundary conditions, as given by `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn7>`__ and `(8) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn7>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The mesh points in the spatial direction. :math:`\mathrm{x}[0]` corresponds to the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` corresponds to the right-hand boundary, :math:`b`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, 3\right)` Contains the value of solution components in the boundary region. If :math:`\mathrm{ibnd} = 0`, :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(\textit{x }, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,3`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. If :math:`\mathrm{ibnd}\neq 0`, :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{npts}-\textit{j}]`, for :math:`\textit{j} = 1,2,\ldots,3`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must evaluate the left-hand boundary condition at :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must evaluate the right-hand boundary condition at :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **g** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{g}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of either :math:`\mathrm{g}^L` or :math:`\mathrm{g}^R` in `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn7>`__ and `(8) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn7>`__, depending on the value of :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` must contain the initial value of :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]` and :math:`t = \mathrm{ts}`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **acc** : float, array-like, shape :math:`\left(2\right)` The components of :math:`\mathrm{acc}` contain the relative and absolute error tolerances used in the local error test in the time integration. If :math:`\mathrm{E}\left(i, j\right)` is the estimated error for :math:`U_i` at the :math:`j`\ th mesh point, the error test is .. math:: \mathrm{E}\left(i, j\right) = \mathrm{acc}[0]\times \mathrm{u}[i-1,j-1]+\mathrm{acc}[1]\text{.} **tsmax** : float The maximum absolute step size to be allowed in the time integration. If :math:`\mathrm{tsmax} = 0.0` then no maximum is imposed. **comm** : dict, communication object, modified in place Communication structure. `On initial entry`: need not be set. **itask** : int The task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` (by overshooting and interpolating). :math:`\mathrm{itask} = 2` Take one step in the time direction and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. **itrace** : int The level of trace information required from ``dim1_parab_convdiff`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_convdiff``. **pdedef** : None or callable (p, c, d, s, ires) = pdedef(t, x, u, ux, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{pdedef}` must evaluate the functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` which partially define the system of PDEs. :math:`P_{{i,j}}`, :math:`C_i` and :math:`S_i` may depend on :math:`x`, :math:`t` and :math:`U`; :math:`D_i` may depend on :math:`x`, :math:`t`, :math:`U` and :math:`U_x`. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_convdiff``. **None** may be used for :math:`\mathrm{pdedef}` for problems in the form `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn2>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}\right)` :math:`\mathrm{p}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **c** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{c}[\textit{i}-1]` must be set to the value of :math:`C_{\textit{i}}\left(x, t, U\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **d** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{d}[\textit{i}-1]` must be set to the value of :math:`D_{\textit{i}}\left(x, t, U, U_x\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **s** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{s}[\textit{i}-1]` must be set to the value of :math:`S_{\textit{i}}\left(x, t, U\right)`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{u}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. Two-dimensional arrays returned from callback functions in this routine must then use the same storage order. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` will contain the computed solution :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]` and :math:`t = \mathrm{ts}`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`. **ind** : int :math:`\mathrm{ind} = 1`. .. _d03pf-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{tsmax} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tsmax}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{acc}[0]` and :math:`\mathrm{acc}[1]` are both zero. (`errno` :math:`1`) On entry, :math:`\mathrm{acc}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{acc}[1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{acc}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{acc}[0]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2` or :math:`3`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) Values in :math:`\mathrm{acc}` are too small to start integration: :math:`\mathrm{acc}[0] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, or :math:`\mathrm{bndary}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`14`) The functions :math:`P`, :math:`D`, or :math:`C` appear to depend on time derivatives. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{acc}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc}[0] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, or :math:`\mathrm{bndary}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{acc}` are unlikely to result in a changed solution. :math:`\mathrm{acc}[0] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{acc}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pf-py2-py-notes: **Notes** ``dim1_parab_convdiff`` integrates the system of convection-diffusion equations in conservative form: .. math:: \sum_{{j = 1}}^{\textit{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+\frac{{\partial F_i}}{{\partial x}} = C_i\frac{{\partial D_i}}{{\partial x}}+S_i\text{,} or the hyperbolic convection-only system: .. math:: \frac{{\partial U_i}}{{\partial t}}+\frac{{\partial F_i}}{{\partial x}} = 0\text{,} for :math:`i = 1,2,\ldots,\textit{npde}\text{, }\quad a\leq x\leq b\text{, }\quad t\geq t_0`, where the vector :math:`U` is the set of solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\textit{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{.} The functions :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` depend on :math:`x`, :math:`t` and :math:`U`; and :math:`D_i` depends on :math:`x`, :math:`t`, :math:`U` and :math:`U_x`, where :math:`U_x` is the spatial derivative of :math:`U`. Note that :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` must not depend on any space derivatives; and none of the functions may depend on time derivatives. In terms of conservation laws, :math:`F_i`, :math:`\frac{{C_i\partial D_i}}{{\partial x}}` and :math:`S_i` are the convective flux, diffusion and source terms respectively. The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}`. The initial values of the functions :math:`U\left(x, t\right)` must be given at :math:`t = t_0`. The PDEs are approximated by a system of ODEs in time for the values of :math:`U_i` at mesh points using a spatial discretization method similar to the central-difference scheme used in :meth:`dim1_parab_fd`, :meth:`dim1_parab_dae_fd` and :meth:`dim1_parab_remesh_fd`, but with the flux :math:`F_i` replaced by a `numerical flux`, which is a representation of the flux taking into account the direction of the flow of information at that point (i.e., the direction of the characteristics). Simple central differencing of the numerical flux then becomes a sophisticated upwind scheme in which the correct direction of upwinding is automatically achieved. The numerical flux vector, :math:`\hat{F}_i` say, must be calculated by you in terms of the `left` and `right` values of the solution vector :math:`U` (denoted by :math:`U_L` and :math:`U_R` respectively), at each mid-point of the mesh :math:`x_{{j-1/2}} = \left(x_{{j-1}}+x_j\right)/2`, for :math:`j = 2,3,\ldots,\textit{npts}`. The left and right values are calculated by ``dim1_parab_convdiff`` from two adjacent mesh points using a standard upwind technique combined with a Van Leer slope-limiter (see LeVeque (1990)). The physically correct value for :math:`\hat{F}_i` is derived from the solution of the Riemann problem given by .. math:: \frac{{\partial U_i}}{{\partial t}}+\frac{{\partial F_i}}{{\partial y}} = 0\text{,} where :math:`y = x-x_{{j-1/2}}`, i.e., :math:`y = 0` corresponds to :math:`x = x_{{j-1/2}}`, with discontinuous initial values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`, using an `approximate Riemann solver`. This applies for either of the systems `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn1>`__ and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn1>`__; the numerical flux is independent of the functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i`. A description of several approximate Riemann solvers can be found in LeVeque (1990) and Berzins `et al.` (1989). Roe's scheme (see Roe (1981)) is perhaps the easiest to understand and use, and a brief summary follows. Consider the system of PDEs :math:`U_t+F_x = 0` or equivalently :math:`U_t+AU_x = 0`. Provided the system is linear in :math:`U`, i.e., the Jacobian matrix :math:`A` does not depend on :math:`U`, the numerical flux :math:`\hat{F}` is given by .. math:: \hat{F} = \frac{1}{2}\left(F_L+F_R\right)-\frac{1}{2}\sum_{{k = 1}}^{\textit{npde}}\alpha_k\left\lvert \lambda_k\right\rvert e_k\text{,} where :math:`F_L` (:math:`F_R`) is the flux :math:`F` calculated at the left (right) value of :math:`U`, denoted by :math:`U_L` (:math:`U_R`); the :math:`\lambda_k` are the eigenvalues of :math:`A`; the :math:`e_k` are the right eigenvectors of :math:`A`; and the :math:`\alpha_k` are defined by .. math:: U_R-U_L = \sum_{{k = 1}}^{\textit{npde}}\alpha_ke_k\text{.} If the system is nonlinear, Roe's scheme requires that a linearized Jacobian is found (see Roe (1981)). The functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` (but **not** :math:`F_i`) must be specified in a :math:`\mathrm{pdedef}`. The numerical flux :math:`\hat{F}_i` must be supplied in a separate :math:`\mathrm{numflx}`. For problems in the form `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pff.html#eqn2>`__, the actual argument **None** may be used for :math:`\mathrm{pdedef}`. This sets the matrix with entries :math:`P_{{i,j}}` to the identity matrix, and the functions :math:`C_i`, :math:`D_i` and :math:`S_i` to zero. The boundary condition specification has sufficient flexibility to allow for different types of problems. For second-order problems, i.e., :math:`D_i` depending on :math:`U_x`, a boundary condition is required for each PDE at both boundaries for the problem to be well-posed. If there are no second-order terms present, then the continuous PDE problem generally requires exactly one boundary condition for each PDE, that is :math:`\textit{npde}` boundary conditions in total. However, in common with most discretization schemes for first-order problems, a `numerical boundary condition` is required at the other boundary for each PDE. In order to be consistent with the characteristic directions of the PDE system, the numerical boundary conditions must be derived from the solution inside the domain in some manner (see below). You must supply both types of boundary conditions, i.e., a total of :math:`\textit{npde}` conditions at each boundary point. The position of each boundary condition should be chosen with care. In simple terms, if information is flowing into the domain then a physical boundary condition is required at that boundary, and a numerical boundary condition is required at the other boundary. In many cases the boundary conditions are simple, e.g., for the linear advection equation. In general you should calculate the characteristics of the PDE system and specify a physical boundary condition for each of the characteristic variables associated with incoming characteristics, and a numerical boundary condition for each outgoing characteristic. A common way of providing numerical boundary conditions is to extrapolate the characteristic variables from the inside of the domain. Note that only linear extrapolation is allowed in this function (for greater flexibility the function :meth:`dim1_parab_convdiff_dae` should be used). For problems in which the solution is known to be uniform (in space) towards a boundary during the period of integration then extrapolation is unnecessary; the numerical boundary condition can be supplied as the known solution at the boundary. The boundary conditions must be specified in :math:`\mathrm{bndary}` in the form .. math:: G_i^L\left(x, t, U\right) = 0\quad \text{ at }x = a\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{,} at the left-hand boundary, and .. math:: G_i^R\left(x, t, U\right) = 0\quad \text{ at }x = b\text{, }\quad i = 1,2,\ldots,\textit{npde}\text{,} at the right-hand boundary. Note that spatial derivatives at the boundary are not passed explicitly to :math:`\mathrm{bndary}`, but they can be calculated using values of :math:`U` at and adjacent to the boundaries if required. However, it should be noted that instabilities may occur if such one-sided differencing opposes the characteristic direction at the boundary. The problem is subject to the following restrictions: (i) :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` must not depend on any space derivatives; (#) :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i`, :math:`D_i` and :math:`S_i` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) The evaluation of the terms :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` is done by calling the :math:`\mathrm{pdedef}` at a point approximately midway between each pair of mesh points in turn. Any discontinuities in these functions **must**, therefore, be at one or more of the mesh points :math:`x_1,x_2,\ldots,x_{\textit{npts}}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem. In total there are :math:`\textit{npde}\times \textit{npts}` ODEs in the time direction. This system is then integrated forwards in time using a BDF method. For further details of the algorithm, see Pennington and Berzins (1994) and the references therein. .. _d03pf-py2-py-references: **References** 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 Hirsch, C, 1990, `Numerical Computation of Internal and External Flows, Volume 2: Computational Methods for Inviscid and Viscous Flows`, John Wiley LeVeque, R J, 1990, `Numerical Methods for Conservation Laws`, Birkhäuser Verlag Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 Roe, P L, 1981, `Approximate Riemann solvers, parameter vectors, and difference schemes`, J. Comput. Phys. (43), 357--372 """ raise NotImplementedError
[docs]def dim1_parab_dae_fd(npde, m, ts, tout, pdedef, bndary, u, x, nv, xi, rtol, atol, itol, norm, laopt, algopt, comm, itask, itrace, ind, odedef=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_dae_fd`` integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable, with scope for coupled ordinary differential equations (ODEs). The spatial discretization is performed using finite differences, and the method of lines is employed to reduce the PDEs to a system of ODEs. The resulting system is solved using a backward differentiation formula method or a Theta method (switching between Newton's method and functional iteration). .. _d03ph-py2-py-doc: For full information please refer to the NAG Library document for d03ph https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html .. _d03ph-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **m** : int The coordinate system used: :math:`\mathrm{m} = 0` Indicates Cartesian coordinates. :math:`\mathrm{m} = 1` Indicates cylindrical polar coordinates. :math:`\mathrm{m} = 2` Indicates spherical polar coordinates. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (p, q, r, ires) = pdedef(t, x, u, ux, v, vdot, ires, data=None) :math:`\mathrm{pdedef}` must evaluate the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which define the system of PDEs. The functions may depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`. :math:`Q_i` may depend linearly on :math:`\dot{V}`. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_dae_fd``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`Q_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}\right)` :math:`\mathrm{p}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, U_x, V\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **q** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{q}[\textit{i}-1]` must be set to the value of :math:`Q_{\textit{i}}\left(x, t, U, U_x, V, \dot{V}\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **r** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{r}[\textit{i}-1]` must be set to the value of :math:`R_{\textit{i}}\left(x, t, U, U_x, V\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (beta, gamma, ires) = bndary(t, u, ux, v, vdot, ibnd, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`\beta_i` and :math:`\gamma_i` which describe the boundary conditions, as given in `[equation] <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqnbndary>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`Q_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must set up the coefficients of the left-hand boundary, :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must set up the coefficients of the right-hand boundary, :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **beta** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{beta}[\textit{i}-1]` must be set to the value of :math:`\beta_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **gamma** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{gamma}[\textit{i}-1]` must be set to the value of :math:`\gamma_{\textit{i}}\left(x, t, U, U_x, V, \dot{V}\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` The initial values of the dependent variables defined as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nv** : int The number of coupled ODE components. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. :math:`\mathrm{itol}` indicates to ``dim1_parab_dae_fd`` whether to interpret either or both of :math:`\mathrm{rtol}` or :math:`\mathrm{atol}` as a vector or scalar. The error test to be satisfied is :math:`\left\lVert e_i/w_i\right\rVert < 1.0`, where :math:`w_i` is defined as follows: +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |:math:`\mathrm{itol}`|:math:`\mathrm{rtol}`|:math:`\mathrm{atol}`|:math:`w_i` | +=====================+=====================+=====================+================================================================================+ |1 |scalar |scalar |:math:`\mathrm{rtol}[0]\times \left\lvert U_i\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |2 |scalar |vector |:math:`\mathrm{rtol}[0]\times \left\lvert U_i\right\rvert +\mathrm{atol}[i-1]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |3 |vector |scalar |:math:`\mathrm{rtol}[i-1]\times \left\lvert U_i\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |4 |vector |vector |:math:`\mathrm{rtol}[i-1]\times \left\lvert U_i\right\rvert +\mathrm{atol}[i-1]`| +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ In the above, :math:`e_{\textit{i}}` denotes the estimated local error for the :math:`\textit{i}`\ th component of the coupled PDE/ODE system in time, :math:`\mathrm{u}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{neqn}`. The choice of norm used is defined by the argument :math:`\mathrm{norm}`. **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'M'}` Maximum norm. :math:`\mathrm{norm} = \texttt{'A'}` Averaged :math:`L_2` norm. If :math:`\mathrm{u}_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_2` norm .. math:: \mathrm{u}_{\mathrm{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\left(\mathrm{u}[i-1]/w_i\right)^2}\text{,} while for the maximum norm .. math:: \mathrm{u}_{\mathrm{norm}} = \mathrm{max}_i\left(\left\lvert \mathrm{u}[i-1]/w_i\right\rvert \right)\text{.} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. Note: you are recommended to use the banded option when no coupled ODEs are present (i.e., :math:`\mathrm{nv} = 0`). **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default value is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4` are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0` for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside this range then the default value is used. If the functions regard the Jacobian matrix as numerically singular then increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Is used as a relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int Specifies the task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 2` One step and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_dae_fd`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_dae_fd``. **odedef** : None or callable (f, ires) = odedef(t, v, vdot, xi, ucp, ucpx, rcp, ucpt, ucptx, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`F`, which define the system of ODEs, as given in `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn3>`__. If you wish to compute the solution of a system of PDEs only (:math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling points, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **rcp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` :math:`\mathrm{rcp}[\textit{i}-1,\textit{j}-1]` contains the value of the flux :math:`R_{\textit{i}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucptx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` :math:`\mathrm{ucptx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2U_{\textit{i}}}}{{{\partial x}{\partial t}}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`F` that must be returned in the array :math:`\mathrm{f}`. :math:`\mathrm{ires} = 1` Equation `(5) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn5>`__ must be used. :math:`\mathrm{ires} = -1` Equation `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn6>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **f** : float, array-like, shape :math:`\left(\textit{nv}\right)` On exit, :math:`\mathrm{f}[i-1]` must contain the :math:`i`\ th component of :math:`F` as specified by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{p}` in :math:`\mathrm{pdedef}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03ph-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{x}[0]}, {\mathrm{x}[\textit{npts}-1]}\right]`: :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{npts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \textit{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} \leq 0` or :math:`\mathrm{x}[0]\geq 0.0` (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'A'}` or :math:`\texttt{'M'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`14`) Flux function appears to depend on time derivatives. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03ph-py2-py-notes: **Notes** ``dim1_parab_dae_fd`` integrates the system of parabolic-elliptic equations and coupled ODEs .. math:: \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+Q_i = x^{{-m}}\frac{\partial }{{\partial x}}\left(x^mR_i\right)\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{, }\quad a\leq x\leq b\text{, }\quad t\geq t_0\text{,} .. math:: F_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, R^*, {U_t^*}, {U_{{xt}}^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{,} where `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn1>`__ defines the PDE part and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn2>`__ generalizes the coupled ODE part of the problem. In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn1>`__, :math:`P_{{i,j}}` and :math:`R_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`; :math:`Q_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`U_x`, :math:`V` and **linearly** on :math:`\dot{V}`. The vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{,} and the vector :math:`U_x` is the partial derivative with respect to :math:`x`. The vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = \left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]^{\mathrm{T}}\text{,} and :math:`\dot{V}` denotes its derivative with respect to time. In `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn2>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to some of the PDE spatial mesh points. :math:`U^*`, :math:`U_x^*`, :math:`R^*`, :math:`U_t^*` and :math:`U_{{xt}}^*` are the functions :math:`U`, :math:`U_x`, :math:`R`, :math:`U_t` and :math:`U_{{xt}}` evaluated at these coupling points. Each :math:`F_i` may only depend linearly on time derivatives. Hence the equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn2>`__ may be written more precisely as .. math:: F = G-A\dot{V}-B\begin{pmatrix}U_t^*\\U_{{xt}}^*\end{pmatrix}\text{,} where :math:`F = \left[F_1, \ldots, F_{\mathrm{nv}}\right]^\mathrm{T}`, :math:`G` is a vector of length :math:`\mathrm{nv}`, :math:`A` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`B` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix and the entries in :math:`G`, :math:`A` and :math:`B` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you only need to supply a vector of information to define the ODEs and not the matrices :math:`A` and :math:`B`. (See :ref:`Parameters <d03ph-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}`. The coordinate system in space is defined by the values of :math:`m`; :math:`m = 0` for Cartesian coordinates, :math:`m = 1` for cylindrical polar coordinates and :math:`m = 2` for spherical polar coordinates. The PDE system which is defined by the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` must be specified in :math:`\mathrm{pdedef}`. The initial values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be given at :math:`t = t_0`. The functions :math:`R_i` which may be thought of as fluxes, are also used in the definition of the boundary conditions. The boundary conditions must have the form .. math:: \beta_i\left(x, t\right)R_i\left(x, t, U, U_x, V\right) = \gamma_i\left(x, t, U, U_x, V, {\dot{V}}\right)\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} where :math:`x = a` or :math:`x = b`. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The function :math:`\gamma_i` may depend **linearly** on :math:`\dot{V}`. The problem is subject to the following restrictions: (i) In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#eqn1>`__, :math:`\dot{V}_{\textit{j}}\left(t\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{nv}`, may only appear **linearly** in the functions :math:`Q_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, with a similar restriction for :math:`\gamma`; (#) :math:`P_{{\textit{i},j}}` and the flux :math:`R_{\textit{i}}` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) the evaluation of the terms :math:`P_{{\textit{i},j}}`, :math:`Q_{\textit{i}}` and :math:`R_{\textit{i}}` is done approximately at the mid-points of the mesh :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, by calling the :math:`\mathrm{pdedef}` for each mid-point in turn. Any discontinuities in these functions **must**, therefore, be at one or more of the mesh points :math:`x_1,x_2,\ldots,x_{\textit{npts}}`; (#) at least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem; (#) if :math:`m > 0` and :math:`x_1 = 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 :math:`x = 0.0` or by specifying a zero flux there, that is :math:`\beta_i = 1.0` and :math:`\gamma_i = 0.0`. See also `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03phf.html#fcomments>`__ below. The algebraic-differential equation system which is defined by the functions :math:`F_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` in the array :math:`\mathrm{xi}`. The parabolic equations are approximated by a system of ODEs in time for the values of :math:`U_i` 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 :math:`\mathrm{npde}\times \textit{npts}+\mathrm{nv}` ODEs in the time direction. This system is then integrated forwards in time using a backward differentiation formula (BDF) or a Theta method. .. _d03ph-py2-py-references: **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 Berzins, M and Furzeland, R M, 1992, `An adaptive theta method for the solution of stiff and nonstiff differential equations`, Appl. Numer. Math. (9), 1--19 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 """ raise NotImplementedError
[docs]def dim1_parab_dae_coll(npde, m, ts, tout, pdedef, bndary, u, xbkpts, npoly, npts, nv, xi, uvinit, rtol, atol, itol, norm, laopt, algopt, comm, itask, itrace, ind, odedef=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_dae_coll`` integrates a system of linear or nonlinear parabolic partial differential equations (PDEs), in one space variable with scope for coupled ordinary differential equations (ODEs). The spatial discretization is performed using a Chebyshev :math:`C^0` collocation method, and the method of lines is employed to reduce the PDEs to a system of ODEs. The resulting system is solved using a backward differentiation formula (BDF) method or a Theta method (switching between Newton's method and functional iteration). .. _d03pj-py2-py-doc: For full information please refer to the NAG Library document for d03pj https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html .. _d03pj-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **m** : int The coordinate system used: :math:`\mathrm{m} = 0` Indicates Cartesian coordinates. :math:`\mathrm{m} = 1` Indicates cylindrical polar coordinates. :math:`\mathrm{m} = 2` Indicates spherical polar coordinates. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (p, q, r, ires) = pdedef(t, x, u, ux, v, vdot, ires, data=None) :math:`\mathrm{pdedef}` must compute the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which define the system of PDEs. The functions may depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`; :math:`Q_i` may depend linearly on :math:`\dot{V}`. The functions must be evaluated at a set of points. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{nptl}\right)` Contains a set of mesh points at which :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` are to be evaluated. :math:`\mathrm{x}[0]` and :math:`\mathrm{x}[\textit{nptl}-1]` contain successive user-supplied break-points and the elements of the array will satisfy :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{nptl}-1]`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{ux}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`Q_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}, \textit{nptl}\right)` :math:`\mathrm{p}[ \mathrm{npde}\times \mathrm{npde}\times \left(\textit{k}-1\right)+ \mathrm{npde}\times \left(\textit{j}-1\right)+ \left(\textit{i}-1\right)]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, U_x, V\right)` where :math:`x = \mathrm{x}[\textit{k}-1]`, for :math:`\textit{k} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **q** : float, array-like, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{q}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`Q_{\textit{i}}\left(x, t, U, U_x, V, \dot{V}\right)` where :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **r** : float, array-like, shape :math:`\left(\textit{npde}, \textit{nptl}\right)` :math:`\mathrm{r}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`R_{\textit{i}}\left(x, t, U, U_x, V\right)` where :math:`x = \mathrm{x}[\textit{i}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{nptl}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_coll`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (beta, gamma, ires) = bndary(t, u, ux, v, vdot, ibnd, ires, data=None) :math:`\mathrm{bndary}` must compute the functions :math:`\beta_i` and :math:`\gamma_i` which define the boundary conditions as in equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn4>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`Q_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must set up the coefficients of the left-hand boundary, :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must set up the coefficients of the right-hand boundary, :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **beta** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{beta}[\textit{i}-1]` must be set to the value of :math:`\beta_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **gamma** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{gamma}[\textit{i}-1]` must be set to the value of :math:`\gamma_{\textit{i}}\left(x, t, U, U_x, V, \dot{V}\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_coll`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` If :math:`\mathrm{ind} = 1` the value of :math:`\mathrm{u}` must be unchanged from the previous call. **xbkpts** : float, array-like, shape :math:`\left(\textit{nbkpts}\right)` The values of the break-points in the space direction. :math:`\mathrm{xbkpts}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{xbkpts}[\textit{nbkpts}-1]` must specify the right-hand boundary, :math:`b`. **npoly** : int The degree of the Chebyshev polynomial to be used in approximating the PDE solution between each pair of break-points. **npts** : int The number of mesh points in the interval :math:`\left[a, b\right]`. **nv** : int The number of coupled ODE components. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points. **uvinit** : callable (u, v) = uvinit(npde, x, nv, data=None) :math:`\mathrm{uvinit}` must compute the initial values of the PDE and the ODE components :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t_0\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`. **Parameters** **npde** : int The number of PDEs in the system. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`, contains the current values of the space variable :math:`x_{\textit{i}}`. **nv** : int The number of coupled ODEs in the system. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\mathrm{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, array-like, shape :math:`\left(\mathrm{nv}\right)` :math:`\mathrm{v}[\textit{i}-1]` contains the value of component :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. :math:`\mathrm{itol}` indicates to ``dim1_parab_dae_coll`` whether to interpret either or both of :math:`\mathrm{rtol}` or :math:`\mathrm{atol}` as a vector or scalar. The error test to be satisfied is :math:`\left\lVert e_i/w_i\right\rVert < 1.0`, where :math:`w_i` is defined as follows: +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |:math:`\mathrm{itol}`|:math:`\mathrm{rtol}`|:math:`\mathrm{atol}`|:math:`w_i` | +=====================+=====================+=====================+================================================================================+ |1 |scalar |scalar |:math:`\mathrm{rtol}[0]\times \left\lvert U_i\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |2 |scalar |vector |:math:`\mathrm{rtol}[0]\times \left\lvert U_i\right\rvert +\mathrm{atol}[i-1]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |3 |vector |scalar |:math:`\mathrm{rtol}[i-1]\times \left\lvert U_i\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |4 |vector |vector |:math:`\mathrm{rtol}[i-1]\times \left\lvert U_i\right\rvert +\mathrm{atol}[i-1]`| +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ In the above, :math:`e_{\textit{i}}` denotes the estimated local error for the :math:`\textit{i}`\ th component of the coupled PDE/ODE system in time, :math:`\mathrm{u}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{neqn}`. The choice of norm used is defined by the argument :math:`\mathrm{norm}`. **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'M'}` Maximum norm. :math:`\mathrm{norm} = \texttt{'A'}` Averaged :math:`L_2` norm. If :math:`\mathrm{u}_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_2` norm .. math:: \mathrm{u}_{\mathrm{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\left(\mathrm{u}[i-1]/w_i\right)^2}\text{,} while for the maximum norm .. math:: \mathrm{u}_{\mathrm{norm}} = \mathrm{max}_i\left(\left\lvert \mathrm{u}[i-1]/w_i\right\rvert \right)\text{.} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. Note: you are recommended to use the banded option when no coupled ODEs are present (i.e., :math:`\mathrm{nv} = 0`). **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default value is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4` are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0` for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside this range then the default value is used. If the functions regard the Jacobian matrix as numerically singular then increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Is used as a relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int Specifies the task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 2` One step and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_dae_coll`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_dae_coll``. **odedef** : None or callable (f, ires) = odedef(t, v, vdot, xi, ucp, ucpx, rcp, ucpt, ucptx, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`F`, which define the system of ODEs, as given in `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn3>`__. If you wish to compute the solution of a system of PDEs only (:math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling points, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **rcp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` :math:`\mathrm{rcp}[\textit{i}-1,\textit{j}-1]` contains the value of the flux :math:`R_{\textit{i}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucptx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` :math:`\mathrm{ucptx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2U_{\textit{i}}}}{{{\partial x}{\partial t}}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`F` that must be returned in the array :math:`\mathrm{f}`. :math:`\mathrm{ires} = 1` Equation `(5) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn5>`__ must be used. :math:`\mathrm{ires} = -1` Equation `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn6>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **f** : float, array-like, shape :math:`\left(\textit{nv}\right)` On exit, :math:`\mathrm{f}[i-1]` must contain the :math:`i`\ th component of :math:`F` as specified by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_coll`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{p}` in :math:`\mathrm{pdedef}` and :math:`\mathrm{r}` in :math:`\mathrm{pdedef}` or :math:`\mathrm{u}` in :math:`\mathrm{uvinit}` are spiked (i.e., have unit extent in all but one dimension, or have size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with them in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\mathrm{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, ndarray, shape :math:`\left(\mathrm{npts}\right)` The mesh points chosen by ``dim1_parab_dae_coll`` in the spatial direction. The values of :math:`\mathrm{x}` will satisfy :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\mathrm{npts}-1]`. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03pj-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{xbkpts}[0]}, {\mathrm{xbkpts}[\textit{nbkpts}-1]}\right]`: :math:`\mathrm{xbkpts}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xbkpts}[\textit{nbkpts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xbkpts}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xbkpts}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xbkpts}[0] < \mathrm{xbkpts}[1] < \cdots < \mathrm{xbkpts}[\textit{nbkpts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \mathrm{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{nbkpts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npts} = \left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{nbkpts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nbkpts}\geq 2`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xbkpts}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} \leq 0` or :math:`\mathrm{xbkpts}[0]\geq 0.0` (`errno` :math:`1`) On entry, :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npoly}\leq 49`. (`errno` :math:`1`) On entry, :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npoly}\geq 1`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'A'}` or :math:`\texttt{'M'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{algopt}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{algopt}[0] = 0.0`, :math:`1.0` or :math:`2.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`14`) Flux function appears to depend on time derivatives. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pj-py2-py-notes: **Notes** ``dim1_parab_dae_coll`` integrates the system of parabolic-elliptic equations and coupled ODEs .. math:: \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+Q_i = x^{{-m}}\frac{\partial }{{\partial x}}\left(x^mR_i\right)\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{, }\quad a\leq x\leq b,t\geq t_0\text{,} .. math:: F_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, R^*, {U_t^*}, {U_{{xt}}^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{,} where `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn1>`__ defines the PDE part and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn2>`__ generalizes the coupled ODE part of the problem. In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn1>`__, :math:`P_{{i,j}}` and :math:`R_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x`, and :math:`V`; :math:`Q_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`U_x`, :math:`V` and **linearly** on :math:`\dot{V}`. The vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{,} and the vector :math:`U_x` is the partial derivative with respect to :math:`x`. Note that :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` must not depend on :math:`\frac{{\partial U}}{{\partial t}}`. The vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = {\left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]}^{\mathrm{T}}\text{,} and :math:`\dot{V}` denotes its derivative with respect to time. In `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn2>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to some of the PDE spatial mesh points. :math:`U^*`, :math:`U_x^*`, :math:`R^*`, :math:`U_t^*` and :math:`U_{{xt}}^*` are the functions :math:`U`, :math:`U_x`, :math:`R`, :math:`U_t` and :math:`U_{{xt}}` evaluated at these coupling points. Each :math:`F_i` may only depend linearly on time derivatives. Hence the equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn2>`__ may be written more precisely as .. math:: F = G-A\dot{V}-B\begin{pmatrix}U_t^*\\U_{{xt}}^*\end{pmatrix}\text{,} where :math:`F = {\left[F_1, \ldots, F_{\mathrm{nv}}\right]}^\mathrm{T}`, :math:`G` is a vector of length :math:`\mathrm{nv}`, :math:`A` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`B` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix and the entries in :math:`G`, :math:`A` and :math:`B` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you need only supply a vector of information to define the ODEs and not the matrices :math:`A` and :math:`B`. (See :ref:`Parameters <d03pj-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{nbkpts}}` are the leftmost and rightmost of a user-defined set of break-points :math:`x_1,x_2,\ldots,x_{\textit{nbkpts}}`. The coordinate system in space is defined by the value of :math:`m`; :math:`m = 0` for Cartesian coordinates, :math:`m = 1` for cylindrical polar coordinates and :math:`m = 2` for spherical polar coordinates. The PDE system which is defined by the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` must be specified in :math:`\mathrm{pdedef}`. The initial values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be given at :math:`t = t_0`. These values are calculated in :math:`\mathrm{uvinit}`. The functions :math:`R_i` which may be thought of as fluxes, are also used in the definition of the boundary conditions. The boundary conditions must have the form .. math:: \beta_i\left(x, t\right)R_i\left(x, t, U, U_x, V\right) = \gamma_i\left(x, t, U, U_x, V, {\dot{V}}\right)\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} where :math:`x = a` or :math:`x = b`. The functions :math:`\gamma_i` may only depend **linearly** on :math:`\dot{V}`. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The algebraic-differential equation system which is defined by the functions :math:`F_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` in the array :math:`\mathrm{xi}`. Thus, the problem is subject to the following restrictions: (i) in `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pjf.html#eqn1>`__, :math:`\dot{V}_{\textit{j}}\left(t\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{nv}`, may only appear **linearly** in the functions :math:`Q_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, with a similar restriction for :math:`\gamma`; (#) :math:`P_{{\textit{i},j}}` and the flux :math:`R_{\textit{i}}` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) the evaluation of the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` is done at both the break-points and internally selected points for each element in turn, that is :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` are evaluated twice at each break-point. Any discontinuities in these functions **must**, therefore, be at one or more of the mesh points; (#) at least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem; (#) if :math:`m > 0` and :math:`x_1 = 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 either by specifying the solution at :math:`x = 0.0` or by specifying a zero flux there, that is :math:`\beta_i = 1.0` and :math:`\gamma_i = 0.0`. The parabolic equations are approximated by a system of ODEs in time for the values of :math:`U_i` 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 :math:`\mathrm{npoly}`. The interval between each pair of break-points is treated by ``dim1_parab_dae_coll`` as an element, and on this element, a polynomial and its space and time derivatives are made to satisfy the system of PDEs at :math:`\mathrm{npoly}-1` spatial points, which are chosen internally by the code and the break-points. The user-defined break-points and the internally selected points together define the mesh. The smallest value that :math:`\mathrm{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 :math:`\left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1` mesh points in the spatial direction, and :math:`\mathrm{npde}\times \left(\left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1\right)+\mathrm{nv}` ODEs in the time direction; one ODE at each break-point for each PDE component, :math:`\mathrm{npoly}-1` ODEs for each PDE component between each pair of break-points, and :math:`\mathrm{nv}` coupled ODEs. The system is then integrated forwards in time using a Backward Differentiation Formula (BDF) method or a Theta method. .. _d03pj-py2-py-references: **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 Berzins, M, Dew, P M and Furzeland, R M, 1988, `Software tools for time-dependent equations in simulation and optimization of large systems`, Proc. IMA Conf. Simulation and Optimization, (ed A J Osiadcz), 35--50, Clarendon Press, Oxford Berzins, M and Furzeland, R M, 1992, `An adaptive theta method for the solution of stiff and nonstiff differential equations`, Appl. Numer. Math. (9), 1--19 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) """ raise NotImplementedError
[docs]def dim1_parab_dae_keller(npde, ts, tout, pdedef, bndary, u, x, nleft, nv, xi, rtol, atol, itol, norm, laopt, algopt, comm, itask, itrace, ind, odedef=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None): r""" ``dim1_parab_dae_keller`` integrates a system of linear or nonlinear, first-order, time-dependent partial differential equations (PDEs) in one space variable, with scope for coupled ordinary differential equations (ODEs). The spatial discretization is performed using the Keller box scheme and the method of lines is employed to reduce the PDEs to a system of ODEs. The resulting system is solved using a Backward Differentiation Formula (BDF) method or a Theta method (switching between Newton's method and functional iteration). .. _d03pk-py2-py-doc: For full information please refer to the NAG Library document for d03pk https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html .. _d03pk-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (res, ires) = pdedef(t, x, u, ut, ux, v, vdot, ires, data=None) :math:`\mathrm{pdedef}` must evaluate the functions :math:`G_i` which define the system of PDEs. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_dae_keller``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ut** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial t}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **ires** : int The form of :math:`G_i` that must be returned in the array :math:`\mathrm{res}`. :math:`\mathrm{ires} = -1` Equation `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn9>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn10>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{res}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`G`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, where :math:`G` is defined as .. math:: G_{\textit{i}} = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}P_{{\textit{i},\textit{j}}}\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}Q_{{\textit{i},\textit{j}}}\dot{V}_{\textit{j}}\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: G_{\textit{i}} = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}P_{{\textit{i},\textit{j}}}\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}Q_{{\textit{i},\textit{j}}}\dot{V}_{\textit{j}}+S_{\textit{i}}\text{,} i.e., all terms in equation `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn3>`__. The definition of :math:`G` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (res, ires) = bndary(t, ibnd, nobc, u, ut, v, vdot, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_i^L` and :math:`G_i^R` which describe the boundary conditions, as given in `(5) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn5>`__ and `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn5>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must compute the left-hand boundary condition at :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must compute the right-hand boundary condition at :math:`x = b`. **nobc** : int Specifies the number of boundary conditions at the boundary specified by :math:`\mathrm{ibnd}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ut** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial t}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\mathrm{vdot}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly as in `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn7>`__ and `(8) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn7>`__. **ires** : int The form of :math:`G_i^L` (or :math:`G_i^R`) that must be returned in the array :math:`\mathrm{res}`. :math:`\mathrm{ires} = -1` Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn11>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn12>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\mathrm{nobc}\right)` :math:`\mathrm{res}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`G^L` or :math:`G^R`, depending on the value of :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nobc}`, where :math:`G^L` is defined as .. math:: G_{\textit{i}}^L = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}E_{{\textit{i},\textit{j}}}^L\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}H_{{\textit{i},\textit{j}}}^L\dot{V}_{\textit{j}}\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: G_{\textit{i}}^L = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}E_{{\textit{i},\textit{j}}}^L\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}H_{{\textit{i},\textit{j}}}^L\dot{V}_{\textit{j}}+K_{\textit{i}}^L\text{,} i.e., all terms in equation `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn7>`__, and similarly for :math:`G_{\textit{i}}^R`. The definitions of :math:`G^L` and :math:`G^R` are determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` The initial values of the dependent variables defined as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nleft** : int The number :math:`n_a` of boundary conditions at the left-hand mesh point :math:`\mathrm{x}[0]`. **nv** : int The number of coupled ODE components. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points, :math:`\xi_{\textit{i}}`. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. :math:`\mathrm{itol}` indicates to ``dim1_parab_dae_keller`` whether to interpret either or both of :math:`\mathrm{rtol}` or :math:`\mathrm{atol}` as a vector or scalar. The error test to be satisfied is :math:`\left\lVert e_i/w_i\right\rVert < 1.0`, where :math:`w_i` is defined as follows: +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------------------+ |:math:`\mathrm{itol}`|:math:`\mathrm{rtol}`|:math:`\mathrm{atol}`|:math:`w_i` | +=====================+=====================+=====================+============================================================================================+ |1 |scalar |scalar |:math:`\mathrm{rtol}[0]\times \left\lvert \mathrm{u}[i-1]\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------------------+ |2 |scalar |vector |:math:`\mathrm{rtol}[0]\times \left\lvert \mathrm{u}[i-1]\right\rvert +\mathrm{atol}[i-1]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------------------+ |3 |vector |scalar |:math:`\mathrm{rtol}[i-1]\times \left\lvert \mathrm{u}[i-1]\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------------------+ |4 |vector |vector |:math:`\mathrm{rtol}[i-1]\times \left\lvert \mathrm{u}[i-1]\right\rvert +\mathrm{atol}[i-1]`| +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------------------+ In the above, :math:`e_{\textit{i}}` denotes the estimated local error for the :math:`\textit{i}`\ th component of the coupled PDE/ODE system in time, :math:`\mathrm{u}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{neqn}`. The choice of norm used is defined by the argument :math:`\mathrm{norm}`. **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'M'}` Maximum norm. :math:`\mathrm{norm} = \texttt{'A'}` Averaged :math:`L_2` norm. If :math:`\mathrm{u}_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_2` norm .. math:: \mathrm{u}_{\mathrm{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\left(\mathrm{u}[i-1]/w_i\right)^2}\text{,} while for the maximum norm .. math:: \mathrm{u}_{\mathrm{norm}} = \mathrm{max}_i\left(\left\lvert \mathrm{u}[i-1]/w_i\right\rvert \right)\text{.} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default value is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, then :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4`, are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0`, for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, i.e., :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside this range then the default value is used. If the functions regard the Jacobian matrix as numerically singular then increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Used as a relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. :math:`\mathrm{algopt}[29]` must be greater than zero, otherwise the default value is used. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int The task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` (by overshooting and interpolating). :math:`\mathrm{itask} = 2` Take one step in the time direction and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_dae_keller`` and the underlying ODE solver as follows: :math:`\mathrm{itrace}\leq -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} = 1` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. :math:`\mathrm{itrace} = 2` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 1`, except that the advisory messages are given in greater detail. :math:`\mathrm{itrace}\geq 3` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 2`, except that the advisory messages are given in greater detail. You advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_dae_keller``. **odedef** : None or callable (r, ires) = odedef(t, v, vdot, xi, ucp, ucpx, ucpt, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`R`, which define the system of ODEs, as given in `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn4>`__. If you wish to compute the solution of a system of PDEs only (i.e., :math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling points, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`R` that must be returned in the array :math:`\mathrm{r}`. :math:`\mathrm{ires} = -1` Equation `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn13>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn14>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **r** : float, array-like, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{r}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`R`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, where :math:`R` is defined as .. math:: R = -B\dot{V}-CU_t^*\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: R = A-B\dot{V}-CU_t^*\text{,} i.e., all terms in equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn4>`__. The definition of :math:`R` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_dae_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **Returns** **ts** : float The value of :math:`t` corresponding to the solution in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03pk-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{x}[0]}, {\mathrm{x}[\textit{npts}-1]}\right]`: :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{npts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \textit{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nleft} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nleft}\leq \mathrm{npde}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nleft} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nleft}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'A'}` or :math:`\texttt{'M'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pk-py2-py-notes: **Notes** ``dim1_parab_dae_keller`` integrates the system of first-order PDEs and coupled ODEs .. math:: G_i\left(x, t, U, U_x, U_t, V, {\dot{V}}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{, }\quad a\leq x\leq b,t\geq t_0\text{,} .. math:: R_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, {U_t^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{.} In the PDE part of the problem given by `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn1>`__, the functions :math:`G_i` must have the general form .. math:: G_i = \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+\sum_{{j = 1}}^{\mathrm{nv}}Q_{{i,j}}\dot{V}_j+S_i = 0\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} where :math:`P_{{i,j}}`, :math:`Q_{{i,j}}` and :math:`S_i` depend on :math:`x,t,U,U_x` and :math:`V`. The vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = \left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]^{\mathrm{T}}\text{,} and the vector :math:`U_x` is the partial derivative with respect to :math:`x`. The vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = {\left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]}^{\mathrm{T}}\text{,} and :math:`\dot{V}` denotes its derivative with respect to time. In the ODE part given by `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn2>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to some of the PDE spatial mesh points. :math:`U^*`, :math:`U_x^*` and :math:`U_t^*` are the functions :math:`U`, :math:`U_x` and :math:`U_t` evaluated at these coupling points. Each :math:`R_i` may only depend linearly on time derivatives. Hence equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pkf.html#eqn2>`__ may be written more precisely as .. math:: R = A-B\dot{V}-CU_t^*\text{,} where :math:`R = \left[R_1, \ldots, R_{\mathrm{nv}}\right]^\mathrm{T}`, :math:`A` is a vector of length :math:`\mathrm{nv}`, :math:`B` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`C` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix. The entries in :math:`A`, :math:`B` and :math:`C` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you only need to supply a vector of information to define the ODEs and not the matrices :math:`B` and :math:`C`. (See :ref:`Parameters <d03pk-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}`. The PDE system which is defined by the functions :math:`G_i` must be specified in :math:`\mathrm{pdedef}`. The initial values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be given at :math:`t = t_0`. For a first-order system of PDEs, only one boundary condition is required for each PDE component :math:`U_i`. The :math:`\mathrm{npde}` boundary conditions are separated into :math:`n_a` at the left-hand boundary :math:`x = a`, and :math:`n_b` at the right-hand boundary :math:`x = b`, such that :math:`n_a+n_b = \mathrm{npde}`. The position of the boundary condition for each component should be chosen with care; the general rule is that if the characteristic direction of :math:`U_i` at the left-hand boundary (say) points into the interior of the solution domain, then the boundary condition for :math:`U_i` should be specified at the left-hand boundary. Incorrect positioning of boundary conditions generally results in initialization or integration difficulties in the underlying time integration functions. The boundary conditions have the form: .. math:: G_i^L\left(x, t, U, U_t, V, \dot{ V }\right) = 0\quad \text{ at }x = a\text{, }\quad i = 1,2,\ldots,n_a\text{,} at the left-hand boundary, and .. math:: G_i^R\left(x, t, U, U_t, V, \dot{ V }\right) = 0\quad \text{ at }x = b\text{, }\quad i = 1,2,\ldots,n_b\text{,} at the right-hand boundary. Note that the functions :math:`G_i^L` and :math:`G_i^R` must not depend on :math:`U_x`, since spatial derivatives are not determined explicitly in the Keller box scheme. If the problem involves derivative (Neumann) boundary conditions then it is generally possible to restate such boundary conditions in terms of permissible variables. Also note that :math:`G_i^L` and :math:`G_i^R` must be linear with respect to time derivatives, so that the boundary conditions have the general form: .. math:: \sum_{{j = 1}}^{\mathrm{npde}}E_{{i,j}}^L\frac{{\partial U_j}}{{\partial t}}+\sum_{{j = 1}}^{\mathrm{nv}}H_{{i,j}}^L\dot{V}_j+K_i^L = 0\text{, }\quad i = 1,2,\ldots,n_a\text{,} at the left-hand boundary, and .. math:: \sum_{{j = 1}}^{\mathrm{npde}}E_{{i,j}}^R\frac{{\partial U_j}}{{\partial t}}+\sum_{{j = 1}}^{\mathrm{nv}}H_{{i,j}}^R\dot{V}_j+K_i^R = 0\text{, }\quad i = 1,2,\ldots,n_b\text{,} at the right-hand boundary, where :math:`E_{{i,j}}^L`, :math:`E_{{i,j}}^R`, :math:`H_{{i,j}}^L`, :math:`H_{{i,j}}^R`, :math:`K_i^L` and :math:`K_i^R` depend on :math:`x,t,U` and :math:`V` only. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The problem is subject to the following restrictions: (i) :math:`P_{{i,j}}`, :math:`Q_{{i,j}}` and :math:`S_i` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) The evaluation of the function :math:`G_i` is done approximately at the mid-points of the mesh :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, by calling the :math:`\mathrm{pdedef}` for each mid-point in turn. Any discontinuities in the function **must**, therefore, be at one or more of the mesh points :math:`x_1,x_2,\ldots,x_{\textit{npts}}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem. The algebraic-differential equation system which is defined by the functions :math:`R_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` in the array :math:`\mathrm{xi}`. The parabolic equations are approximated by a system of ODEs in time for the values of :math:`U_i` at mesh points. In this method of lines approach the Keller box scheme (see Keller (1970)) is applied to each PDE in the space variable only, resulting in a system of ODEs in time for the values of :math:`U_i` at each mesh point. In total there are :math:`\mathrm{npde}\times \textit{npts}+\mathrm{nv}` ODEs in time direction. This system is then integrated forwards in time using a Backward Differentiation Formula (BDF) or a Theta method. .. _d03pk-py2-py-references: **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 Berzins, M and Furzeland, R M, 1992, `An adaptive theta method for the solution of stiff and nonstiff differential equations`, Appl. Numer. Math. (9), 1--19 Keller, H B, 1970, `A new difference scheme for parabolic problems`, Numerical Solutions of Partial Differential Equations, (ed J Bramble) (2), 327--350, Academic Press Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 """ raise NotImplementedError
[docs]def dim1_parab_convdiff_dae(npde, ts, tout, numflx, bndary, u, x, nv, xi, rtol, atol, itol, norm, laopt, algopt, comm, itask, itrace, ind, pdedef=None, odedef=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_convdiff_dae`` integrates a system of linear or nonlinear convection-diffusion equations in one space dimension, with optional source terms and scope for coupled ordinary differential equations (ODEs). The system must be posed in conservative form. Convection terms are discretized using a sophisticated upwind scheme involving a user-supplied numerical flux function based on the solution of a Riemann problem at each mesh point. The method of lines is employed to reduce the partial differential equations (PDEs) to a system of ODEs, and the resulting system is solved using a backward differentiation formula (BDF) method or a Theta method. .. _d03pl-py2-py-doc: For full information please refer to the NAG Library document for d03pl https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html .. _d03pl-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **numflx** : callable (flux, ires) = numflx(t, x, v, uleft, uright, ires, data=None) :math:`\mathrm{numflx}` must supply the numerical flux for each PDE given the `left` and `right` values of the solution vector :math:`\mathrm{u}`. :math:`\mathrm{numflx}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_convdiff_dae``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **uleft** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{uleft}[\textit{i}-1]` contains the `left` value of the component :math:`U_{\textit{i}}\left(x\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **uright** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{uright}[\textit{i}-1]` contains the `right` value of the component :math:`U_{\textit{i}}\left(x\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **flux** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{flux}[\textit{i}-1]` must be set to the numerical flux :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_dae`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (g, ires) = bndary(t, x, u, v, vdot, ibnd, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_i^L` and :math:`G_i^R` which describe the physical and numerical boundary conditions, as given by `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn9>`__ and `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn9>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The mesh points in the spatial direction. :math:`\mathrm{x}[0]` corresponds to the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` corresponds to the right-hand boundary, :math:`b`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. Note: if banded matrix algebra is to be used then the functions :math:`G_{\textit{i}}^L` and :math:`G_{\textit{i}}^R` may depend on the value of :math:`U_{\textit{i}}\left(x, t\right)` at the boundary point and the two adjacent points only. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`G_{\textit{j}}^L` and :math:`G_{\textit{j}}^R`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must evaluate the left-hand boundary condition at :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must evaluate the right-hand boundary condition at :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **g** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{g}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of either :math:`G_{\textit{i}}^L` or :math:`G_{\textit{i}}^R` in `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn9>`__ and `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn9>`__, depending on the value of :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_dae`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` The initial values of the dependent variables defined as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nv** : int The number of coupled ODE components. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. If :math:`e_{\textit{i}}` is the estimated local error for :math:`\mathrm{u}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{neqn}`, and :math:`\left\lVert \quad \text{ }\quad \right\rVert` denotes the norm, the error test to be satisfied is :math:`\left\lVert e_{\textit{i}}\right\rVert < 1.0`. :math:`\mathrm{itol}` indicates to ``dim1_parab_convdiff_dae`` whether to interpret either or both of :math:`\mathrm{rtol}` and :math:`\mathrm{atol}` as a vector or scalar in the formation of the weights :math:`w_{\textit{i}}` used in the calculation of the norm (see the description of :math:`\mathrm{norm}`): +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |:math:`\mathrm{itol}`|:math:`\mathrm{rtol}`|:math:`\mathrm{atol}`|:math:`w_{\textit{i}}` | +=====================+=====================+=====================+=======================================================================================================================+ |1 |scalar |scalar |:math:`\mathrm{rtol}[0]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |2 |scalar |vector |:math:`\mathrm{rtol}[0]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[\textit{i}-1]` | +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |3 |vector |scalar |:math:`\mathrm{rtol}[\textit{i}-1]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |4 |vector |vector |:math:`\mathrm{rtol}[\textit{i}-1]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[\textit{i}-1]`| +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'1'}` Averaged :math:`L_1` norm. :math:`\mathrm{norm} = \texttt{'2'}` Averaged :math:`L_2` norm. If :math:`U_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_1` norm .. math:: U_{\text{norm}} = \frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\mathrm{u}[i-1]/w_i\text{,} and for the averaged :math:`L_2` norm .. math:: U_{\text{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\left(\mathrm{u}[i-1]/w_i\right)^2}\text{.} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. Note: you are recommended to use the banded option when no coupled ODEs are present (:math:`\mathrm{nv} = 0`). Also, the banded option should not be used if the boundary conditions involve solution components at points other than the boundary and the immediately adjacent two points. **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, then :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4`, are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0` for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, i.e., :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside the range then the default value is used. If the functions regard the Jacobian matrix as numerically singular, increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Used as the relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. :math:`\mathrm{algopt}[29]` must be greater than zero, otherwise the default value is used. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian matrix is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int The task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` (by overshooting and interpolating). :math:`\mathrm{itask} = 2` Take one step in the time direction and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_convdiff_dae`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` should be reset between calls to ``dim1_parab_convdiff_dae``. **pdedef** : None or callable (p, c, d, s, ires) = pdedef(t, x, u, ux, v, vdot, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{pdedef}` must evaluate the functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` which partially define the system of PDEs. :math:`P_{{i,j}}` and :math:`C_i` may depend on :math:`x`, :math:`t`, :math:`U` and :math:`V`; :math:`D_i` may depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`; and :math:`S_i` may depend on :math:`x`, :math:`t`, :math:`U`, :math:`V` and linearly on :math:`\dot{V}`. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_convdiff_dae``. **None** may be used for :math:`\mathrm{pdedef}` for problems in the form `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn2>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`S_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}\right)` :math:`\mathrm{p}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, V\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **c** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{c}[\textit{i}-1]` must be set to the value of :math:`C_{\textit{i}}\left(x, t, U, V\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **d** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{d}[\textit{i}-1]` must be set to the value of :math:`D_{\textit{i}}\left(x, t, U, U_x, V\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **s** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{s}[\textit{i}-1]` must be set to the value of :math:`S_{\textit{i}}\left(x, t, U, V, {\dot{V}}\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_dae`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **odedef** : None or callable (r, ires) = odedef(t, v, vdot, xi, ucp, ucpx, ucpt, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`R`, which define the system of ODEs, as given in `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn4>`__. If you wish to compute the solution of a system of PDEs only (i.e., :math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling point, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`R` that must be returned in the array :math:`\mathrm{r}`. :math:`\mathrm{ires} = 1` Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn11>`__ must be used. :math:`\mathrm{ires} = -1` Equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn12>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **r** : float, array-like, shape :math:`\left(\textit{nv}\right)` :math:`\mathrm{r}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`R`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, where :math:`R` is defined as .. math:: R = L-M\dot{V}-NU_t^*\text{,} or .. math:: R = -M\dot{V}-NU_t^*\text{.} The definition of :math:`R` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_dae`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{p}` in :math:`\mathrm{pdedef}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03pl-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{x}[0]}, {\mathrm{x}[\textit{npts}-1]}\right]`: :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{npts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \textit{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'1'}` or :math:`\texttt{'2'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, :math:`\mathrm{bndary}` or :math:`\mathrm{odedef}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in a call to functions :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, :math:`\mathrm{bndary}` or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`14`) The functions :math:`P`, :math:`D`, or :math:`C` appear to depend on time derivatives. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in functions :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, :math:`\mathrm{bndary}` or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pl-py2-py-notes: **Notes** ``dim1_parab_convdiff_dae`` integrates the system of convection-diffusion equations in conservative form: .. math:: \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+\frac{{\partial F_i}}{{\partial x}} = C_i\frac{{\partial D_i}}{{\partial x}}+S_i\text{,} or the hyperbolic convection-only system: .. math:: \frac{{\partial U_i}}{{\partial t}}+\frac{{\partial F_i}}{{\partial x}} = 0\text{,} for :math:`i = 1,2,\ldots,\mathrm{npde}\text{, }\quad a\leq x\leq b\text{, }\quad t\geq t_0`, where the vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = {\left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]}^{\mathrm{T}}\text{.} The optional coupled ODEs are of the general form .. math:: R_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, {U_t^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{,} where the vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = {\left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]}^{\mathrm{T}}\text{,} :math:`\dot{V}` denotes its derivative with respect to time, and :math:`U_x` is the spatial derivative of :math:`U`. In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn1>`__, :math:`P_{{i,j}}`, :math:`F_i` and :math:`C_i` depend on :math:`x`, :math:`t`, :math:`U` and :math:`V`; :math:`D_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`; and :math:`S_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`V` and **linearly** on :math:`\dot{V}`. Note that :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` must not depend on any space derivatives, and :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`D_i` must not depend on any time derivatives. In terms of conservation laws, :math:`F_i`, :math:`\frac{{C_i\partial D_i}}{{\partial x}}` and :math:`S_i` are the convective flux, diffusion and source terms respectively. In `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn3>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to PDE spatial mesh points. :math:`U^*`, :math:`U_x^*` and :math:`U_t^*` are the functions :math:`U`, :math:`U_x` and :math:`U_t` evaluated at these coupling points. Each :math:`R_i` may depend only linearly on time derivatives. Hence `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn3>`__ may be written more precisely as .. math:: R = L-M\dot{V}-NU_t^*\text{,} where :math:`R = \left[R_1, \ldots, R_{\mathrm{nv}}\right]^\mathrm{T}`, :math:`L` is a vector of length :math:`\mathrm{nv}`, :math:`M` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`N` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix and the entries in :math:`L`, :math:`M` and :math:`N` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you only need to supply a vector of information to define the ODEs and not the matrices :math:`L`, :math:`M` and :math:`N`. (See :ref:`Parameters <d03pl-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}`. The initial values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be given at :math:`t = t_0`. The PDEs are approximated by a system of ODEs in time for the values of :math:`U_i` at mesh points using a spatial discretization method similar to the central-difference scheme used in :meth:`dim1_parab_fd`, :meth:`dim1_parab_dae_fd` and :meth:`dim1_parab_remesh_fd`, but with the flux :math:`F_i` replaced by a `numerical flux`, which is a representation of the flux taking into account the direction of the flow of information at that point (i.e., the direction of the characteristics). Simple central differencing of the numerical flux then becomes a sophisticated upwind scheme in which the correct direction of upwinding is automatically achieved. The numerical flux vector, :math:`\hat{F}_i` say, must be calculated by you in terms of the `left` and `right` values of the solution vector :math:`U` (denoted by :math:`U_L` and :math:`U_R` respectively), at each mid-point of the mesh :math:`x_{{\textit{j}-\frac{1}{2}}} = \left(x_{{\textit{j}-1}}+x_{\textit{j}}\right)/2`, for :math:`\textit{j} = 2,3,\ldots,\textit{npts}`. The left and right values are calculated by ``dim1_parab_convdiff_dae`` from two adjacent mesh points using a standard upwind technique combined with a Van Leer slope-limiter (see LeVeque (1990)). The physically correct value for :math:`\hat{F}_i` is derived from the solution of the Riemann problem given by .. math:: \frac{{\partial U_i}}{{\partial t}}+\frac{{\partial F_i}}{{\partial y}} = 0\text{,} where :math:`y = x-x_{{j-\frac{1}{2}}}`, i.e., :math:`y = 0` corresponds to :math:`x = x_{{j-\frac{1}{2}}}`, with discontinuous initial values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`, using an `approximate Riemann solver`. This applies for either of the systems `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn1>`__ and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn1>`__; the numerical flux is independent of the functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i`. A description of several approximate Riemann solvers can be found in LeVeque (1990) and Berzins `et al.` (1989). Roe's scheme (see Roe (1981)) is perhaps the easiest to understand and use, and a brief summary follows. Consider the system of PDEs :math:`U_t+F_x = 0` or equivalently :math:`U_t+AU_x = 0`. Provided the system is linear in :math:`U`, i.e., the Jacobian matrix :math:`A` does not depend on :math:`U`, the numerical flux :math:`\hat{F}` is given by .. math:: \hat{F} = \frac{1}{2}\left(F_L+F_R\right)-\frac{1}{2}\sum_{{k = 1}}^{\mathrm{npde}}\alpha_k\left\lvert \lambda_k\right\rvert e_k\text{,} where :math:`F_L` (:math:`F_R`) is the flux :math:`F` calculated at the left (right) value of :math:`U`, denoted by :math:`U_L` (:math:`U_R`); the :math:`\lambda_k` are the eigenvalues of :math:`A`; the :math:`e_k` are the right eigenvectors of :math:`A`; and the :math:`\alpha_k` are defined by .. math:: U_R-U_L = \sum_{{k = 1}}^{\mathrm{npde}}\alpha_ke_k\text{.} If the system is nonlinear, Roe's scheme requires that a linearized Jacobian is found (see Roe (1981)). The functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` (but **not** :math:`F_i`) must be specified in :math:`\mathrm{pdedef}`. The numerical flux :math:`\hat{F}_i` must be supplied in a separate :math:`\mathrm{numflx}`. For problems in the form `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn2>`__, the actual argument **None** may be used for :math:`\mathrm{pdedef}`. This sets the matrix with entries :math:`P_{{i,j}}` to the identity matrix, and the functions :math:`C_i`, :math:`D_i` and :math:`S_i` to zero. The boundary condition specification has sufficient flexibility to allow for different types of problems. For second-order problems, i.e., :math:`D_i` depending on :math:`U_x`, a boundary condition is required for each PDE at both boundaries for the problem to be well-posed. If there are no second-order terms present, then the continuous PDE problem generally requires exactly one boundary condition for each PDE, that is :math:`\mathrm{npde}` boundary conditions in total. However, in common with most discretization schemes for first-order problems, a `numerical boundary condition` is required at the other boundary for each PDE. In order to be consistent with the characteristic directions of the PDE system, the numerical boundary conditions must be derived from the solution inside the domain in some manner (see below). You must supply both types of boundary condition, i.e., a total of :math:`\mathrm{npde}` conditions at each boundary point. The position of each boundary condition should be chosen with care. In simple terms, if information is flowing into the domain then a physical boundary condition is required at that boundary, and a numerical boundary condition is required at the other boundary. In many cases the boundary conditions are simple, e.g., for the linear advection equation. In general you should calculate the characteristics of the PDE system and specify a physical boundary condition for each of the characteristic variables associated with incoming characteristics, and a numerical boundary condition for each outgoing characteristic. A common way of providing numerical boundary conditions is to extrapolate the characteristic variables from the inside of the domain (note that when using banded matrix algebra the fixed bandwidth means that only linear extrapolation is allowed, i.e., using information at just two interior points adjacent to the boundary). For problems in which the solution is known to be uniform (in space) towards a boundary during the period of integration then extrapolation is unnecessary; the numerical boundary condition can be supplied as the known solution at the boundary. Another method of supplying numerical boundary conditions involves the solution of the characteristic equations associated with the outgoing characteristics. Examples of both methods can be found in the :meth:`dim1_parab_convdiff` documentation. The boundary conditions must be specified in :math:`\mathrm{bndary}` in the form .. math:: G_i^L\left(x, t, U, V, {\dot{V}}\right) = 0\quad \text{ at }x = a\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} at the left-hand boundary, and .. math:: G_i^R\left(x, t, U, V, {\dot{V}}\right) = 0\quad \text{ at }x = b\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} at the right-hand boundary. Note that spatial derivatives at the boundary are not passed explicitly to :math:`\mathrm{bndary}`, but they can be calculated using values of :math:`U` at and adjacent to the boundaries if required. However, it should be noted that instabilities may occur if such one-sided differencing opposes the characteristic direction at the boundary. The algebraic-differential equation system which is defined by the functions :math:`R_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` (if any) in the array :math:`\mathrm{xi}`. The problem is subject to the following restrictions: (i) In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03plf.html#eqn1>`__, :math:`\dot{V}_j\left(t\right)`, for :math:`j = 1,2,\ldots,\mathrm{nv}`, may only appear **linearly** in the functions :math:`S_i`, for :math:`i = 1,2,\ldots,\mathrm{npde}`, with a similar restriction for :math:`G_i^L` and :math:`G_i^R`; (#) :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` must not depend on any space derivatives; and :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`D_i` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) The evaluation of the terms :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` is done by calling the :math:`\mathrm{pdedef}` at a point approximately midway between each pair of mesh points in turn. Any discontinuities in these functions **must**, therefore, be at one or more of the mesh points :math:`x_1,x_2,\ldots,x_{\textit{npts}}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem. In total there are :math:`\mathrm{npde}\times \textit{npts}+\mathrm{nv}` ODEs in the time direction. This system is then integrated forwards in time using a BDF or Theta method, optionally switching between Newton's method and functional iteration (see Berzins `et al.` (1989)). For further details of the scheme, see Pennington and Berzins (1994) and the references therein. .. _d03pl-py2-py-references: **References** 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 Hirsch, C, 1990, `Numerical Computation of Internal and External Flows, Volume 2: Computational Methods for Inviscid and Viscous Flows`, John Wiley LeVeque, R J, 1990, `Numerical Methods for Conservation Laws`, Birkhäuser Verlag Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 Roe, P L, 1981, `Approximate Riemann solvers, parameter vectors, and difference schemes`, J. Comput. Phys. (43), 357--372 Sod, G A, 1978, `A survey of several finite difference methods for systems of nonlinear hyperbolic conservation laws`, J. Comput. Phys. (27), 1--31 """ raise NotImplementedError
[docs]def dim1_parab_remesh_fd(npde, m, ts, tout, pdedef, bndary, uvinit, u, x, nv, xi, rtol, atol, itol, norm, laopt, algopt, remesh, xfix, nrmesh, dxmesh, trmesh, ipminf, comm, itask, itrace, ind, odedef=None, xratio=1.5, con=None, monitf=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_remesh_fd`` integrates a system of linear or nonlinear parabolic partial differential equations (PDEs) in one space variable, with scope for coupled ordinary differential equations (ODEs), and automatic adaptive spatial remeshing. The spatial discretization is performed using finite differences, and the method of lines is employed to reduce the PDEs to a system of ODEs. The resulting system is solved using a Backward Differentiation Formula (BDF) method or a Theta method (switching between Newton's method and functional iteration). .. _d03pp-py2-py-doc: For full information please refer to the NAG Library document for d03pp https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html .. _d03pp-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **m** : int The coordinate system used: :math:`\mathrm{m} = 0` Indicates Cartesian coordinates. :math:`\mathrm{m} = 1` Indicates cylindrical polar coordinates. :math:`\mathrm{m} = 2` Indicates spherical polar coordinates. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (p, q, r, ires) = pdedef(t, x, u, ux, v, vdot, ires, data=None) :math:`\mathrm{pdedef}` must evaluate the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` which define the system of PDEs. The functions may depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`. :math:`Q_i` may depend linearly on :math:`\dot{V}`. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_remesh_fd``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`Q_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}\right)` :math:`\mathrm{p}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, U_x, V\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **q** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{q}[\textit{i}-1]` must be set to the value of :math:`Q_{\textit{i}}\left(x, t, U, U_x, V, \dot{V}\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **r** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{r}[\textit{i}-1]` must be set to the value of :math:`R_{\textit{i}}\left(x, t, U, U_x, V\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_remesh_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (beta, gamma, ires) = bndary(t, u, ux, v, vdot, ibnd, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`\beta_i` and :math:`\gamma_i` which describe the boundary conditions, as given in `[equation] <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqnbndary>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`\gamma_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must set up the coefficients of the left-hand boundary, :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must set up the coefficients of the right-hand boundary, :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **beta** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{beta}[\textit{i}-1]` must be set to the value of :math:`\beta_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **gamma** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{gamma}[\textit{i}-1]` must be set to the value of :math:`\gamma_{\textit{i}}\left(x, t, U, U_x, V, \dot{V}\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_remesh_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **uvinit** : callable (u, v) = uvinit(npde, x, xi, nv, data=None) :math:`\mathrm{uvinit}` must supply the initial :math:`\left(t = t_0\right)` values of :math:`U\left(x, t\right)` and :math:`V\left(t\right)` for all values of :math:`x` in the interval :math:`a\leq x\leq b`. **Parameters** **npde** : int The number of PDEs in the system. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The current mesh. :math:`\mathrm{x}[\textit{i}-1]` contains the value of :math:`x_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the value of the ODE/PDE coupling point, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **nv** : int The number of coupled ODEs in the system. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\mathrm{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, array-like, shape :math:`\left(\mathrm{nv}\right)` :math:`\mathrm{v}[\textit{i}-1]` contains the value of component :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` If :math:`\mathrm{ind} = 1` the value of :math:`\mathrm{u}` must be unchanged from the previous call. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The initial mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nv** : int The number of coupled ODE in the system. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. :math:`\mathrm{itol}` indicates to ``dim1_parab_remesh_fd`` whether to interpret either or both of :math:`\mathrm{rtol}` or :math:`\mathrm{atol}` as a vector or scalar. The error test to be satisfied is :math:`\left\lVert e_i/w_i\right\rVert < 1.0`, where :math:`w_i` is defined as follows: +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |:math:`\mathrm{itol}`|:math:`\mathrm{rtol}`|:math:`\mathrm{atol}`|:math:`w_i` | +=====================+=====================+=====================+================================================================================+ |1 |scalar |scalar |:math:`\mathrm{rtol}[0]\times \left\lvert U_i\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |2 |scalar |vector |:math:`\mathrm{rtol}[0]\times \left\lvert U_i\right\rvert +\mathrm{atol}[i-1]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |3 |vector |scalar |:math:`\mathrm{rtol}[i-1]\times \left\lvert U_i\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ |4 |vector |vector |:math:`\mathrm{rtol}[i-1]\times \left\lvert U_i\right\rvert +\mathrm{atol}[i-1]`| +---------------------+---------------------+---------------------+--------------------------------------------------------------------------------+ In the above, :math:`e_{\textit{i}}` denotes the estimated local error for the :math:`\textit{i}`\ th component of the coupled PDE/ODE system in time, :math:`\mathrm{u}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{neqn}`. The choice of norm used is defined by the argument :math:`\mathrm{norm}`. **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'M'}` Maximum norm. :math:`\mathrm{norm} = \texttt{'A'}` Averaged :math:`L_2` norm. If :math:`\mathrm{u}_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_2` norm .. math:: \mathrm{u}_{\mathrm{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\left(\mathrm{u}[i-1]/w_i\right)^2}\text{,} while for the maximum norm .. math:: \mathrm{u}_{\mathrm{norm}} = \mathrm{max}_i\left(\left\lvert \mathrm{u}[i-1]/w_i\right\rvert \right)\text{.} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. Note: you are recommended to use the banded option when no coupled ODEs are present (i.e., :math:`\mathrm{nv} = 0`). **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default value is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4` are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0` for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside this range then the default value is used. If the functions regard the Jacobian matrix as numerically singular then increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Is used as a relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **remesh** : bool Indicates whether or not spatial remeshing should be performed. :math:`\mathrm{remesh} = \mathbf{True}` Indicates that spatial remeshing should be performed as specified. :math:`\mathrm{remesh} = \mathbf{False}` Indicates that spatial remeshing should be suppressed. Note: :math:`\mathrm{remesh}` should **not** be changed between consecutive calls to ``dim1_parab_remesh_fd``. Remeshing can be switched off or on at specified times by using appropriate values for the arguments :math:`\mathrm{nrmesh}` and :math:`\mathrm{trmesh}` at each call. **xfix** : float, array-like, shape :math:`\left(\textit{nxfix}\right)` :math:`\mathrm{xfix}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxfix}`, must contain the value of the :math:`x` coordinate at the :math:`\textit{i}`\ th fixed mesh point. **nrmesh** : int Specifies the spatial remeshing frequency and criteria for the calculation and adoption of a new mesh. :math:`\mathrm{nrmesh} < 0` Indicates that a new mesh is adopted according to the argument :math:`\mathrm{dxmesh}`. The mesh is tested every :math:`\left\lvert \mathrm{nrmesh}\right\rvert` timesteps. :math:`\mathrm{nrmesh} = 0` Indicates that remeshing should take place just once at the end of the first time step reached when :math:`t > \mathrm{trmesh}`. :math:`\mathrm{nrmesh} > 0` Indicates that remeshing will take place every :math:`\mathrm{nrmesh}` time steps, with no testing using :math:`\mathrm{dxmesh}`. Note: :math:`\mathrm{nrmesh}` may be changed between consecutive calls to ``dim1_parab_remesh_fd`` to give greater flexibility over the times of remeshing. **dxmesh** : float Determines whether a new mesh is adopted when :math:`\mathrm{nrmesh}` is set less than zero. A possible new mesh is calculated at the end of every :math:`\left\lvert \mathrm{nrmesh}\right\rvert` time steps, but is adopted only if .. math:: x_i^{\left(\mathrm{new}\right)} > x_i^{\left(\mathrm{old}\right)}+\mathrm{dxmesh}\times \left(x_{{i+1}}^{\left(\mathrm{old}\right)}-x_i^{\left(\mathrm{old}\right)}\right) or .. math:: x_i^{\left(\mathrm{new}\right)} < x_i^{\left(\mathrm{old}\right)}-\mathrm{dxmesh}\times \left(x_i^{\left(\mathrm{old}\right)}-x_{{i-1}}^{\left(\mathrm{old}\right)}\right) :math:`\mathrm{dxmesh}` thus imposes a lower limit on the difference between one mesh and the next. **trmesh** : float Specifies when remeshing will take place when :math:`\mathrm{nrmesh}` is set to zero. Remeshing will occur just once at the end of the first time step reached when :math:`t` is greater than :math:`\mathrm{trmesh}`. Note: :math:`\mathrm{trmesh}` may be changed between consecutive calls to ``dim1_parab_remesh_fd`` to force remeshing at several specified times. **ipminf** : int The level of trace information regarding the adaptive remeshing. Details are directed to the file object associated with the advisory I/O unit (see :class:`~naginterfaces.base.utils.FileObjManager`). :math:`\mathrm{ipminf} = 0` No trace information. :math:`\mathrm{ipminf} = 1` Brief summary of mesh characteristics. :math:`\mathrm{ipminf} = 2` More detailed information, including old and new mesh points, mesh sizes and monitor function values. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int Specifies the task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 2` One step and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_remesh_fd`` and the underlying ODE solver: :math:`\mathrm{itrace}\leq -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} = 1` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. :math:`\mathrm{itrace} = 2` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 1`, except that the advisory messages are given in greater detail. :math:`\mathrm{itrace}\geq 3` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 2`, except that the advisory messages are given in greater detail. **ind** : int Must be set to :math:`0` or :math:`1`. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` and the remeshing arguments :math:`\mathrm{nrmesh}`, :math:`\mathrm{dxmesh}`, :math:`\mathrm{trmesh}`, :math:`\mathrm{xratio}` and :math:`\mathrm{con}` may be reset between calls to ``dim1_parab_remesh_fd``. **odedef** : None or callable (f, ires) = odedef(t, v, vdot, xi, ucp, ucpx, rcp, ucpt, ucptx, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`F`, which define the system of ODEs, as given in `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn3>`__. If you wish to compute the solution of a system of PDEs only (:math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling points, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **rcp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` :math:`\mathrm{rcp}[\textit{i}-1,\textit{j}-1]` contains the value of the flux :math:`R_{\textit{i}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucptx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` :math:`\mathrm{ucptx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2U_{\textit{i}}}}{{{\partial x}{\partial t}}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`F` that must be returned in the array :math:`\mathrm{f}`. :math:`\mathrm{ires} = 1` Equation `(5) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn5>`__ must be used. :math:`\mathrm{ires} = -1` Equation `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn6>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **f** : float, array-like, shape :math:`\left(\textit{nv}\right)` On exit, :math:`\mathrm{f}[i-1]` must contain the :math:`i`\ th component of :math:`F` as specified by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_remesh_fd`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **xratio** : float, optional An input bound on the adjacent mesh ratio (greater than :math:`1.0` and typically in the range :math:`1.5` to :math:`3.0`). The remeshing functions will attempt to ensure that .. math:: \left(x_i-x_{{i-1}}\right)/\mathrm{xratio} < x_{{i+1}}-x_i < \mathrm{xratio}\times \left(x_i-x_{{i-1}}\right)\text{.} **con** : None or float, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`2.0/\left(\textit{npts}-1\right)`. An input bound on the sub-integral of the monitor function :math:`F^{\mathrm{mon}}\left(x\right)` over each space step. The remeshing functions will attempt to ensure that .. math:: \int_{x_i}^{x_{{i+1}}}F^{\mathrm{mon}}\left(x\right){dx}\leq \mathrm{con}\int_{x_1}^{x_{\textit{npts}}}F^{\mathrm{mon}}\left(x\right){dx}\text{,} (see Furzeland (1984)). :math:`\mathrm{con}` gives you more control over the mesh distribution e.g., decreasing :math:`\mathrm{con}` allows more clustering. A typical value is :math:`2/\left(\textit{npts}-1\right)`, but you are encouraged to experiment with different values. Its value is not critical and the mesh should be qualitatively correct for all values in the range given below. **monitf** : None or callable fmon = monitf(t, x, u, r, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{monitf}` must supply and evaluate a remesh monitor function to indicate the solution behaviour of interest. If you specify :math:`\mathrm{remesh} = \mathbf{False}`, i.e., no remeshing, :math:`\mathrm{monitf}` will not be called and may be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The current mesh. :math:`\mathrm{x}[\textit{i}-1]` contains the value of :math:`x_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]` and time :math:`t`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **r** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{r}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`R_{\textit{i}}\left(x, t, U, U_x, V\right)` at :math:`x = \mathrm{x}[\textit{j}-1]` and time :math:`t`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **fmon** : float, array-like, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{fmon}[i-1]` must contain the value of the monitor function :math:`F^{\mathrm{mon}}\left(x\right)` at mesh point :math:`x = \mathrm{x}[i-1]`. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{p}` in :math:`\mathrm{pdedef}` or :math:`\mathrm{u}` in :math:`\mathrm{uvinit}` are spiked (i.e., have unit extent in all but one dimension, or have size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with them in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The final values of the mesh points. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03pp-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, the point :math:`\mathrm{xfix}[\textit{i}-1]` does not coincide with any :math:`\mathrm{x}[\textit{j}-1]`: :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xfix}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xfix}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xfix}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xfix}[\textit{i}] > \mathrm{xfix}[\textit{i}-1]`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{x}[0]}, {\mathrm{x}[\textit{npts}-1]}\right]`: :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{npts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \textit{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{con} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{con}\leq 10.0/\left(\textit{npts}-1\right)`. (`errno` :math:`1`) On entry, :math:`\mathrm{con} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{con}\geq 0.1/\left(\textit{npts}-1\right)`. (`errno` :math:`1`) On entry, :math:`\mathrm{xratio} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xratio} > 1.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ipminf} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ipminf} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{dxmesh} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dxmesh}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{nxfix} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxfix}\leq \textit{npts}-2`. (`errno` :math:`1`) On entry, :math:`\textit{nxfix} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxfix}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} \leq 0` or :math:`\mathrm{x}[0]\geq 0.0` (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'A'}` or :math:`\texttt{'M'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`14`) Flux function appears to depend on time derivatives. (`errno` :math:`16`) :math:`\mathrm{remesh}` has been changed between calls to ``dim1_parab_remesh_fd``. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pp-py2-py-notes: **Notes** ``dim1_parab_remesh_fd`` integrates the system of parabolic-elliptic equations and coupled ODEs .. math:: \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+Q_i = x^{{-m}}\frac{\partial }{{\partial x}}\left(x^mR_i\right)\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{, }\quad a\leq x\leq b,t\geq t_0\text{,} .. math:: F_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, R^*, {U_t^*}, {U_{{xt}}^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{,} where `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn1>`__ defines the PDE part and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn2>`__ generalizes the coupled ODE part of the problem. In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn1>`__, :math:`P_{{i,j}}` and :math:`R_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x`, and :math:`V`; :math:`Q_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`U_x`, :math:`V` and **linearly** on :math:`\dot{V}`. The vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = {\left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]}^{\mathrm{T}}\text{,} and the vector :math:`U_x` is the partial derivative with respect to :math:`x`. The vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = {\left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]}^{\mathrm{T}}\text{,} and :math:`\dot{V}` denotes its derivative with respect to time. In `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn2>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to some of the PDE spatial mesh points. :math:`U^*`, :math:`U_x^*`, :math:`R^*`, :math:`U_t^*` and :math:`U_{{xt}}^*` are the functions :math:`U`, :math:`U_x`, :math:`R`, :math:`U_t` and :math:`U_{{xt}}` evaluated at these coupling points. Each :math:`F_i` may only depend linearly on time derivatives. Hence the equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn2>`__ may be written more precisely as .. math:: F = G-A\dot{V}-B\begin{pmatrix}U_t^*\\U_{{xt}}^*\end{pmatrix}\text{,} where :math:`F = \left[F_1, \ldots, F_{\mathrm{nv}}\right]^\mathrm{T}`, :math:`G` is a vector of length :math:`\mathrm{nv}`, :math:`A` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`B` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix and the entries in :math:`G`, :math:`A` and :math:`B` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you only need to supply a vector of information to define the ODEs and not the matrices :math:`A` and :math:`B`. (See :ref:`Parameters <d03pp-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}` defined initially by you and (possibly) adapted automatically during the integration according to user-specified criteria. The coordinate system in space is defined by the following values of :math:`m`; :math:`m = 0` for Cartesian coordinates, :math:`m = 1` for cylindrical polar coordinates and :math:`m = 2` for spherical polar coordinates. The PDE system which is defined by the functions :math:`P_{{i,j}}`, :math:`Q_i` and :math:`R_i` must be specified in :math:`\mathrm{pdedef}`. The initial :math:`\left(t = t_0\right)` values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be specified in :math:`\mathrm{uvinit}`. Note that :math:`\mathrm{uvinit}` will be called again following any initial remeshing, and so :math:`U\left(x, t_0\right)` should be specified for **all** values of :math:`x` in the interval :math:`a\leq x\leq b`, and not just the initial mesh points. The functions :math:`R_i` which may be thought of as fluxes, are also used in the definition of the boundary conditions. The boundary conditions must have the form .. math:: \beta_i\left(x, t\right)R_i\left(x, t, U, U_x, V\right) = \gamma_i\left(x, t, U, U_x, V, {\dot{V}}\right)\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} where :math:`x = a` or :math:`x = b`. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The function :math:`\gamma_i` may depend **linearly** on :math:`\dot{V}`. The problem is subject to the following restrictions: (i) In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#eqn1>`__, :math:`\dot{V}_{\textit{j}}\left(t\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{nv}`, may only appear **linearly** in the functions :math:`Q_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, with a similar restriction for :math:`\gamma`; (#) :math:`P_{{i,j}}` and the flux :math:`R_i` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) The evaluation of the terms :math:`P_{{\textit{i},j}}`, :math:`Q_{\textit{i}}` and :math:`R_{\textit{i}}` is done approximately at the mid-points of the mesh :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, by calling the :math:`\mathrm{pdedef}` for each mid-point in turn. Any discontinuities in these functions **must**, therefore, be at one or more of the fixed mesh points specified by :math:`\mathrm{xfix}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem; (#) If :math:`m > 0` and :math:`x_1 = 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 :math:`x = 0.0` or by specifying a zero flux there, that is :math:`\beta_i = 1.0` and :math:`\gamma_i = 0.0`. See also `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03ppf.html#fcomments>`__. The algebraic-differential equation system which is defined by the functions :math:`F_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` in the array :math:`\mathrm{xi}`. The parabolic equations are approximated by a system of ODEs in time for the values of :math:`U_i` 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 :math:`\mathrm{npde}\times \textit{npts}+\mathrm{nv}` ODEs in time direction. This system is then integrated forwards in time using a Backward Differentiation Formula (BDF) or a Theta method. The adaptive space remeshing can be used to generate meshes that automatically follow the changing time-dependent nature of the solution, generally resulting in a more efficient and accurate solution using fewer mesh points than may be necessary with a fixed uniform or non-uniform mesh. Problems with travelling wavefronts or variable-width boundary layers for example will benefit from using a moving adaptive mesh. The discrete time-step method used here (developed by Furzeland (1984)) automatically creates a new mesh based on the current solution profile at certain time-steps, and the solution is then interpolated onto the new mesh and the integration continues. The method requires you to supply a :math:`\mathrm{monitf}` which specifies in an analytical or numerical form the particular aspect of the solution behaviour you wish to track. This so-called monitor function is used to choose a mesh which equally distributes the integral of the monitor function over the domain. A typical choice of monitor function is the second space derivative of the solution value at each point (or some combination of the second space derivatives if there is more than one solution component), which results in refinement in regions where the solution gradient is changing most rapidly. You must specify the frequency of mesh updates together with certain other criteria such as adjacent mesh ratios. Remeshing can be expensive and you are encouraged to experiment with the different options in order to achieve an efficient solution which adequately tracks the desired features of the solution. Note that unless the monitor function for the initial solution values is zero at all user-specified initial mesh points, a new initial mesh is calculated and adopted according to the user-specified remeshing criteria. :math:`\mathrm{uvinit}` will then be called again to determine the initial solution values at the new mesh points (there is no interpolation at this stage) and the integration proceeds. .. _d03pp-py2-py-references: **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 Berzins, M and Furzeland, R M, 1992, `An adaptive theta method for the solution of stiff and nonstiff differential equations`, Appl. Numer. Math. (9), 1--19 Furzeland, R M, 1984, `The construction of adaptive space meshes`, TNER.85.022, Thornton Research Centre, Chester 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 """ raise NotImplementedError
[docs]def dim1_parab_remesh_keller(npde, ts, tout, pdedef, bndary, uvinit, u, x, nleft, nv, xi, rtol, atol, itol, norm, laopt, algopt, remesh, xfix, nrmesh, dxmesh, trmesh, ipminf, comm, itask, itrace, ind, odedef=None, xratio=1.5, con=None, monitf=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_remesh_keller`` integrates a system of linear or nonlinear, first-order, time-dependent partial differential equations (PDEs) in one space variable, with scope for coupled ordinary differential equations (ODEs), and automatic adaptive spatial remeshing. The spatial discretization is performed using the Keller box scheme (see Keller (1970)) and the method of lines is employed to reduce the PDEs to a system of ODEs. The resulting system is solved using a Backward Differentiation Formula (BDF) method or a Theta method (switching between Newton's method and functional iteration). .. _d03pr-py2-py-doc: For full information please refer to the NAG Library document for d03pr https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html .. _d03pr-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **pdedef** : callable (res, ires) = pdedef(t, x, u, ut, ux, v, vdot, ires, data=None) :math:`\mathrm{pdedef}` must evaluate the functions :math:`G_i` which define the system of PDEs. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_remesh_keller``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ut** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial t}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **ires** : int The form of :math:`G_i` that must be returned in the array :math:`\mathrm{res}`. :math:`\mathrm{ires} = -1` Equation `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn9>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn10>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{res}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`G`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, where :math:`G` is defined as .. math:: G_{\textit{i}} = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}P_{{\textit{i},\textit{j}}}\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}Q_{{\textit{i},\textit{j}}}\dot{V}_{\textit{j}}\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: G_{\textit{i}} = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}P_{{\textit{i},\textit{j}}}\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}Q_{{\textit{i},\textit{j}}}\dot{V}_{\textit{j}}+S_{\textit{i}}\text{,} i.e., all terms in equation `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn3>`__. The definition of :math:`G` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_remesh_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (res, ires) = bndary(t, ibnd, nobc, u, ut, v, vdot, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_i^L` and :math:`G_i^R` which describe the boundary conditions, as given in `(5) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn5>`__ and `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn5>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must compute the left-hand boundary condition at :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must compute of the right-hand boundary condition at :math:`x = b`. **nobc** : int Specifies the number :math:`n_a` of boundary conditions at the boundary specified by :math:`\mathrm{ibnd}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at the boundary specified by :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ut** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial t}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\mathrm{vdot}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly as in `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn11>`__ and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn11>`__. **ires** : int The form of :math:`G_i^L` (or :math:`G_i^R`) that must be returned in the array :math:`\mathrm{res}`. :math:`\mathrm{ires} = -1` Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn11>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn12>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\mathrm{nobc}\right)` :math:`\mathrm{res}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`G^L` or :math:`G^R`, depending on the value of :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nobc}`, where :math:`G^L` is defined as .. math:: G_{\textit{i}}^L = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}E_{{\textit{i},\textit{j}}}^L\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}H_{{\textit{i},\textit{j}}}^L\dot{V}_{\textit{j}}\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: G_{\textit{i}}^L = \sum_{{\textit{j} = 1}}^{\mathrm{npde}}E_{{\textit{i},\textit{j}}}^L\frac{{\partial U_{\textit{j}}}}{{\partial t}}+\sum_{{\textit{j} = 1}}^{\mathrm{nv}}H_{{\textit{i},\textit{j}}}^L\dot{V}_{\textit{j}}+K_{\textit{i}}^L\text{,} i.e., all terms in equation `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn7>`__, and similarly for :math:`G_{\textit{i}}^R`. The definitions of :math:`G^L` and :math:`G^R` are determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_remesh_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **uvinit** : callable (u, v) = uvinit(npde, x, xi, nv, data=None) :math:`\mathrm{uvinit}` must supply the initial :math:`\left(t = t_0\right)` values of :math:`U\left(x, t\right)` and :math:`V\left(t\right)` for all values of :math:`x` in the interval :math:`\left[a, b\right]`. **Parameters** **npde** : int The number of PDEs in the system. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The current mesh. :math:`\mathrm{x}[\textit{i}-1]` contains the value of :math:`x_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling point, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **nv** : int The number of coupled ODEs in the system. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\mathrm{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, array-like, shape :math:`\left(\mathrm{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` must contain the value of component :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` If :math:`\mathrm{ind} = 1` the value of :math:`\mathrm{u}` must be unchanged from the previous call. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The initial mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nleft** : int The number :math:`n_a` of boundary conditions at the left-hand mesh point :math:`\mathrm{x}[0]`. **nv** : int The number of coupled ODE components. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points, :math:`\xi_{\textit{i}}`. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. :math:`\mathrm{itol}` indicates to ``dim1_parab_remesh_keller`` whether to interpret either or both of :math:`\mathrm{rtol}` or :math:`\mathrm{atol}` as a vector or scalar. **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'M'}` Maximum norm. :math:`\mathrm{norm} = \texttt{'A'}` Averaged :math:`L_2` norm. If :math:`U_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_2` norm .. math:: U_{\mathrm{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}{\left(U\left(i\right)/w_i\right)}^2}\text{,} while for the maximum norm .. math:: U_{\mathrm{norm}} = \mathrm{max}_i\left\lvert \mathrm{u}[i-1]/w_i\right\rvert \text{.} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default value is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, then :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4`, are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0`, for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, i.e., :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside this range then the default value is used. If the functions regard the Jacobian matrix as numerically singular then increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Used as a relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. :math:`\mathrm{algopt}[29]` must be greater than zero, otherwise the default value is used. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **remesh** : bool Indicates whether or not spatial remeshing should be performed. :math:`\mathrm{remesh} = \mathbf{True}` Indicates that spatial remeshing should be performed as specified. :math:`\mathrm{remesh} = \mathbf{False}` Indicates that spatial remeshing should be suppressed. Note: :math:`\mathrm{remesh}` should **not** be changed between consecutive calls to ``dim1_parab_remesh_keller``. Remeshing can be switched off or on at specified times by using appropriate values for the arguments :math:`\mathrm{nrmesh}` and :math:`\mathrm{trmesh}` at each call. **xfix** : float, array-like, shape :math:`\left(\textit{nxfix}\right)` :math:`\mathrm{xfix}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxfix}`, must contain the value of the :math:`x` coordinate at the :math:`\textit{i}`\ th fixed mesh point. **nrmesh** : int Indicates the form of meshing to be performed. :math:`\mathrm{nrmesh} < 0` Indicates that a new mesh is adopted according to the argument :math:`\mathrm{dxmesh}`. The mesh is tested every :math:`\left\lvert \mathrm{nrmesh}\right\rvert` timesteps. :math:`\mathrm{nrmesh} = 0` Indicates that remeshing should take place just once at the end of the first time step reached when :math:`t > \mathrm{trmesh}`. :math:`\mathrm{nrmesh} > 0` Indicates that remeshing will take place every :math:`\mathrm{nrmesh}` time steps, with no testing using :math:`\mathrm{dxmesh}`. Note: :math:`\mathrm{nrmesh}` may be changed between consecutive calls to ``dim1_parab_remesh_keller`` to give greater flexibility over the times of remeshing. **dxmesh** : float Determines whether a new mesh is adopted when :math:`\mathrm{nrmesh}` is set less than zero. A possible new mesh is calculated at the end of every :math:`\left\lvert \mathrm{nrmesh}\right\rvert` time steps, but is adopted only if .. math:: x_i^{\mathrm{new}} > x_i^{\mathrm{old}}+\mathrm{dxmesh}\times \left(x_{{i+1}}^{\mathrm{old}}-x_i^{\mathrm{old}}\right)\text{,} or .. math:: x_i^{\mathrm{new}} < x_i^{\mathrm{old}}-\mathrm{dxmesh}\times \left(x_i^{\mathrm{old}}-x_{{i-1}}^{\mathrm{old}}\right)\text{.} :math:`\mathrm{dxmesh}` thus imposes a lower limit on the difference between one mesh and the next. **trmesh** : float Specifies when remeshing will take place when :math:`\mathrm{nrmesh}` is set to zero. Remeshing will occur just once at the end of the first time step reached when :math:`t` is greater than :math:`\mathrm{trmesh}`. Note: :math:`\mathrm{trmesh}` may be changed between consecutive calls to ``dim1_parab_remesh_keller`` to force remeshing at several specified times. **ipminf** : int The level of trace information regarding the adaptive remeshing. Details are directed to the file object associated with the advisory I/O unit (see :class:`~naginterfaces.base.utils.FileObjManager`). :math:`\mathrm{ipminf} = 0` No trace information. :math:`\mathrm{ipminf} = 1` Brief summary of mesh characteristics. :math:`\mathrm{ipminf} = 2` More detailed information, including old and new mesh points, mesh sizes and monitor function values. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int The task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` (by overshooting and interpolating). :math:`\mathrm{itask} = 2` Take one step in the time direction and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_remesh_keller`` and the underlying ODE solver as follows: :math:`\mathrm{itrace}\leq -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} = 1` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. :math:`\mathrm{itrace} = 2` Output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 1`, except that the advisory messages are given in greater detail. :math:`\mathrm{itrace}\geq 3` The output from the underlying ODE solver is similar to that produced when :math:`\mathrm{itrace} = 2`, except that the advisory messages are given in greater detail. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the argument :math:`\mathrm{tout}` and the remeshing arguments :math:`\mathrm{nrmesh}`, :math:`\mathrm{dxmesh}`, :math:`\mathrm{trmesh}`, :math:`\mathrm{xratio}` and :math:`\mathrm{con}` may be reset between calls to ``dim1_parab_remesh_keller``. **odedef** : None or callable (r, ires) = odedef(t, v, vdot, xi, ucp, ucpx, ucpt, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`R`, which define the system of ODEs, as given in `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn4>`__. If you wish to compute the solution of a system of PDEs only (i.e., :math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling point, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`R` that must be returned in the array :math:`\mathrm{r}`. :math:`\mathrm{ires} = -1` Equation `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn13>`__ must be used. :math:`\mathrm{ires} = 1` Equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn14>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **r** : float, array-like, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{r}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`R`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, where :math:`R` is defined as .. math:: R = -B\dot{V}-CU_t^*\text{,} i.e., only terms depending explicitly on time derivatives, or .. math:: R = A-B\dot{V}-CU_t^*\text{,} i.e., all terms in equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn4>`__. The definition of :math:`R` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_remesh_keller`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **xratio** : float, optional An input bound on the adjacent mesh ratio (greater than :math:`1.0` and typically in the range :math:`1.5` to :math:`3.0`). The remeshing functions will attempt to ensure that .. math:: \left(x_i-x_{{i-1}}\right)/\mathrm{xratio} < x_{{i+1}}-x_i < \mathrm{xratio}\times \left(x_i-x_{{i-1}}\right)\text{.} **con** : None or float, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`2.0/\left(\textit{npts}-1\right)`. An input bound on the sub-integral of the monitor function :math:`F^{\mathrm{mon}}\left(x\right)` over each space step. The remeshing functions will attempt to ensure that .. math:: \int_{x_1}^{x_{{i+1}}}F^{\mathrm{mon}}\left(x\right){dx}\leq \mathrm{con}\int_{x_1}^{x_{\textit{npts}}}F^{\mathrm{mon}}\left(x\right){dx}\text{,} (see Furzeland (1984)). :math:`\mathrm{con}` gives you more control over the mesh distribution e.g., decreasing :math:`\mathrm{con}` allows more clustering. A typical value is :math:`2/\left(\textit{npts}-1\right)`, but you are encouraged to experiment with different values. Its value is not critical and the mesh should be qualitatively correct for all values in the range given below. **monitf** : None or callable fmon = monitf(t, x, u, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{monitf}` must supply and evaluate a remesh monitor function to indicate the solution behaviour of interest. If you specify :math:`\mathrm{remesh} = \mathbf{False}`, i.e., no remeshing, :math:`\mathrm{monitf}` will not be called and may be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The current mesh. :math:`\mathrm{x}[\textit{i}-1]` contains the value of :math:`x_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]` and time :math:`t`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **fmon** : float, array-like, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{fmon}[i-1]` must contain the value of the monitor function :math:`F^{\mathrm{mon}}\left(x\right)` at mesh point :math:`x = \mathrm{x}[i-1]`. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{u}` in :math:`\mathrm{uvinit}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The final values of the mesh points. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03pr-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, the point :math:`\mathrm{xfix}[\textit{i}-1]` does not coincide with any :math:`\mathrm{x}[\textit{j}-1]`: :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xfix}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xfix}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xfix}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xfix}[\textit{i}] > \mathrm{xfix}[\textit{i}-1]`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{x}[0]}, {\mathrm{x}[\textit{npts}-1]}\right]`: :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{npts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \textit{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{con} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{con}\leq 10.0/\left(\textit{npts}-1\right)`. (`errno` :math:`1`) On entry, :math:`\mathrm{con} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{con}\geq 0.1/\left(\textit{npts}-1\right)`. (`errno` :math:`1`) On entry, :math:`\mathrm{xratio} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xratio} > 1.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ipminf} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ipminf} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{dxmesh} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dxmesh}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{nxfix} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxfix}\leq \textit{npts}-2`. (`errno` :math:`1`) On entry, :math:`\textit{nxfix} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxfix}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nleft} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nleft}\leq \mathrm{npde}`. (`errno` :math:`1`) On entry, :math:`\mathrm{nleft} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nleft}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'A'}` or :math:`\texttt{'M'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}` or :math:`\mathrm{bndary}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in call to :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`16`) :math:`\mathrm{remesh}` has been changed between calls to ``dim1_parab_remesh_keller``. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}`, or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03pr-py2-py-notes: **Notes** ``dim1_parab_remesh_keller`` integrates the system of first-order PDEs and coupled ODEs given by the master equations: .. math:: G_i\left(x, t, U, U_x, U_t, V, {\dot{V}}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{, }\quad a\leq x\leq b,t\geq t_0\text{,} .. math:: R_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, {U_t^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{.} In the PDE part of the problem given by `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn1>`__, the functions :math:`G_i` must have the general form .. math:: G_i = \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+\sum_{{j = 1}}^{\mathrm{nv}}Q_{{i,j}}\dot{V}_j+S_i = 0\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} where :math:`P_{{i,j}}`, :math:`Q_{{i,j}}` and :math:`S_i` depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`. The vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = {\left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]}^{\mathrm{T}}\text{,} and the vector :math:`U_x` is the partial derivative with respect to :math:`x`. The vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = {\left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]}^{\mathrm{T}}\text{,} and :math:`\dot{V}` denotes its derivative with respect to time. In the ODE part given by `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn2>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to some of the PDE spatial mesh points. :math:`U^*`, :math:`U_x^*` and :math:`U_t^*` are the functions :math:`U`, :math:`U_x` and :math:`U_t` evaluated at these coupling points. Each :math:`R_i` may only depend linearly on time derivatives. Hence equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03prf.html#eqn2>`__ may be written more precisely as .. math:: R = A-B\dot{V}-CU_t^*\text{,} where :math:`R = \left[R_1, \ldots, R_{\mathrm{nv}}\right]^\mathrm{T}`, :math:`A` is a vector of length :math:`\mathrm{nv}`, :math:`B` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`C` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix and the entries in :math:`A`, :math:`B` and :math:`C` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you only need to supply a vector of information to define the ODEs and not the matrices :math:`B` and :math:`C`. (See :ref:`Parameters <d03pr-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}` defined initially by you and (possibly) adapted automatically during the integration according to user-specified criteria. The PDE system which is defined by the functions :math:`G_i` must be specified in :math:`\mathrm{pdedef}`. The initial :math:`\left(t = t_0\right)` values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be specified in :math:`\mathrm{uvinit}`. Note that :math:`\mathrm{uvinit}` will be called again following any remeshing, and so :math:`U\left(x, t_0\right)` should be specified for **all** values of :math:`x` in the interval :math:`a\leq x\leq b`, and not just the initial mesh points. For a first-order system of PDEs, only one boundary condition is required for each PDE component :math:`U_i`. The :math:`\mathrm{npde}` boundary conditions are separated into :math:`n_a` at the left-hand boundary :math:`x = a`, and :math:`n_b` at the right-hand boundary :math:`x = b`, such that :math:`n_a+n_b = \mathrm{npde}`. The position of the boundary condition for each component should be chosen with care; the general rule is that if the characteristic direction of :math:`U_i` at the left-hand boundary (say) points into the interior of the solution domain, then the boundary condition for :math:`U_i` should be specified at the left-hand boundary. Incorrect positioning of boundary conditions generally results in initialization or integration difficulties in the underlying time integration functions. The boundary conditions have the master equation form: .. math:: G_i^L\left(x, t, U, U_t, V, {\dot{V}}\right) = 0\quad \text{ at }x = a\text{, }\quad i = 1,2,\ldots,n_a\text{,} at the left-hand boundary, and .. math:: G_i^R\left(x, t, U, U_t, V, {\dot{V}}\right) = 0\quad \text{ at }x = b\text{, }\quad i = 1,2,\ldots,n_b\text{,} at the right-hand boundary. Note that the functions :math:`G_i^L` and :math:`G_i^R` must not depend on :math:`U_x`, since spatial derivatives are not determined explicitly in the Keller box scheme functions. If the problem involves derivative (Neumann) boundary conditions then it is generally possible to restate such boundary conditions in terms of permissible variables. Also note that :math:`G_i^L` and :math:`G_i^R` must be linear with respect to time derivatives, so that the boundary conditions have the general form: .. math:: \sum_{{j = 1}}^{\mathrm{npde}}E_{{i,j}}^L\frac{{\partial U_j}}{{\partial t}}+\sum_{{j = 1}}^{\mathrm{nv}}H_{{i,j}}^L\dot{V}_j+K_i^L = 0\text{, }\quad i = 1,2,\ldots,n_a\text{,} at the left-hand boundary, and .. math:: \sum_{{j = 1}}^{\mathrm{npde}}E_{{i,j}}^R\frac{{\partial U_j}}{{\partial t}}+\sum_{{j = 1}}^{\mathrm{nv}}H_{{i,j}}^R\dot{V}_j+K_i^R = 0\text{, }\quad i = 1,2,\ldots,n_b\text{,} at the right-hand boundary, where :math:`E_{{i,j}}^L`, :math:`E_{{i,j}}^R`, :math:`H_{{i,j}}^L`, :math:`H_{{i,j}}^R`, :math:`K_i^L` and :math:`K_i^R` depend on :math:`x,t,U` and :math:`V` only. The boundary conditions must be specified in :math:`\mathrm{bndary}`. The problem is subject to the following restrictions: (i) :math:`P_{{i,j}}`, :math:`Q_{{i,j}}` and :math:`S_i` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) The evaluation of the function :math:`G_{\textit{i}}` is done approximately at the mid-points of the mesh :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, by calling :math:`\mathrm{pdedef}` for each mid-point in turn. Any discontinuities in the function **must**, therefore, be at one or more of the fixed mesh points specified by :math:`\mathrm{xfix}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem. The algebraic-differential equation system which is defined by the functions :math:`R_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` in the array :math:`\mathrm{xi}`. The first-order equations are approximated by a system of ODEs in time for the values of :math:`U_i` at mesh points. In this method of lines approach the Keller box scheme is applied to each PDE in the space variable only, resulting in a system of ODEs in time for the values of :math:`U_i` at each mesh point. In total there are :math:`\mathrm{npde}\times \textit{npts}+\mathrm{nv}` ODEs in time direction. This system is then integrated forwards in time using a Backward Differentiation Formula (BDF) or a Theta method. The adaptive space remeshing can be used to generate meshes that automatically follow the changing time-dependent nature of the solution, generally resulting in a more efficient and accurate solution using fewer mesh points than may be necessary with a fixed uniform or non-uniform mesh. Problems with travelling wavefronts or variable-width boundary layers for example will benefit from using a moving adaptive mesh. The discrete time-step method used here (developed by Furzeland (1984)) automatically creates a new mesh based on the current solution profile at certain time-steps, and the solution is then interpolated onto the new mesh and the integration continues. The method requires you to supply :math:`\mathrm{monitf}` which specifies in an analytic or numeric form the particular aspect of the solution behaviour you wish to track. This so-called monitor function is used to choose a mesh which equally distributes the integral of the monitor function over the domain. A typical choice of monitor function is the second space derivative of the solution value at each point (or some combination of the second space derivatives if more than one solution component), which results in refinement in regions where the solution gradient is changing most rapidly. You must specify the frequency of mesh updates along with certain other criteria such as adjacent mesh ratios. Remeshing can be expensive and you are encouraged to experiment with the different options in order to achieve an efficient solution which adequately tracks the desired features of the solution. Note that unless the monitor function for the initial solution values is zero at all user-specified initial mesh points, a new initial mesh is calculated and adopted according to the user-specified remeshing criteria. :math:`\mathrm{uvinit}` will then be called again to determine the initial solution values at the new mesh points (there is no interpolation at this stage) and the integration proceeds. .. _d03pr-py2-py-references: **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 Berzins, M and Furzeland, R M, 1992, `An adaptive theta method for the solution of stiff and nonstiff differential equations`, Appl. Numer. Math. (9), 1--19 Furzeland, R M, 1984, `The construction of adaptive space meshes`, TNER.85.022, Thornton Research Centre, Chester Keller, H B, 1970, `A new difference scheme for parabolic problems`, Numerical Solutions of Partial Differential Equations, (ed J Bramble) (2), 327--350, Academic Press Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 """ raise NotImplementedError
[docs]def dim1_parab_convdiff_remesh(npde, ts, tout, numflx, bndary, uvinit, u, x, nv, xi, rtol, atol, itol, norm, laopt, algopt, remesh, xfix, nrmesh, dxmesh, trmesh, ipminf, comm, itask, itrace, ind, pdedef=None, odedef=None, xratio=1.5, con=None, monitf=None, lrsave_estim=0, lisave_estim=0, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim1_parab_convdiff_remesh`` integrates a system of linear or nonlinear convection-diffusion equations in one space dimension, with optional source terms and scope for coupled ordinary differential equations (ODEs). The system must be posed in conservative form. This function also includes the option of automatic adaptive spatial remeshing. Convection terms are discretized using a sophisticated upwind scheme involving a user-supplied numerical flux function based on the solution of a Riemann problem at each mesh point. The method of lines is employed to reduce the partial differential equations (PDEs) to a system of ODEs, and the resulting system is solved using a backward differentiation formula (BDF) method or a Theta method. .. _d03ps-py2-py-doc: For full information please refer to the NAG Library document for d03ps https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html .. _d03ps-py2-py-parameters: **Parameters** **npde** : int The number of PDEs to be solved. **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **numflx** : callable (flux, ires) = numflx(t, x, v, uleft, uright, ires, data=None) :math:`\mathrm{numflx}` must supply the numerical flux for each PDE given the `left` and `right` values of the solution vector :math:`\mathrm{u}`. :math:`\mathrm{numflx}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_convdiff_remesh``. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **uleft** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{uleft}[\textit{i}-1]` contains the `left` value of the component :math:`U_{\textit{i}}\left(x\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **uright** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{uright}[\textit{i}-1]` contains the `right` value of the component :math:`U_{\textit{i}}\left(x\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **flux** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{flux}[\textit{i}-1]` must be set to the numerical flux :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_remesh`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **bndary** : callable (g, ires) = bndary(t, x, u, v, vdot, ibnd, ires, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_i^L` and :math:`G_i^R` which describe the physical and numerical boundary conditions, as given by `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn9>`__ and `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn9>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The mesh points in the spatial direction. :math:`\mathrm{x}[0]` corresponds to the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` corresponds to the right-hand boundary, :math:`b`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. Note: if banded matrix algebra is to be used then the functions :math:`G_{\textit{i}}^L` and :math:`G_{\textit{i}}^R` may depend on the value of :math:`U_{\textit{i}}\left(x, t\right)` at the boundary point and the two adjacent points only. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`G_{\textit{j}}^L` and :math:`G_{\textit{j}}^R`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ibnd** : int Specifies which boundary conditions are to be evaluated. :math:`\mathrm{ibnd} = 0` :math:`\mathrm{bndary}` must evaluate the left-hand boundary condition at :math:`x = a`. :math:`\mathrm{ibnd}\neq 0` :math:`\mathrm{bndary}` must evaluate the right-hand boundary condition at :math:`x = b`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **g** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{g}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of either :math:`G_{\textit{i}}^L` or :math:`G_{\textit{i}}^R` in `(9) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn9>`__ and `(0) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn9>`__, depending on the value of :math:`\mathrm{ibnd}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_remesh`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **uvinit** : callable (u, v) = uvinit(npde, x, xi, nv, data=None) :math:`\mathrm{uvinit}` must supply the initial :math:`\left(t = t_0\right)` values of :math:`U\left(x, t\right)` and :math:`V\left(t\right)` for all values of :math:`x` in the interval :math:`a\leq x\leq b`. **Parameters** **npde** : int The number of PDEs in the system. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The current mesh. :math:`\mathrm{x}[\textit{i}-1]` contains the value of :math:`x_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling point, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **nv** : int The number of coupled ODEs in the system. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\mathrm{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_0\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, array-like, shape :math:`\left(\mathrm{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` must contain the value of component :math:`V_{\textit{i}}\left(t_0\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **u** : float, array-like, shape :math:`\left(\textit{neqn}\right)` If :math:`\mathrm{ind} = 1` the value of :math:`\mathrm{u}` must be unchanged from the previous call. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` The mesh points in the space direction. :math:`\mathrm{x}[0]` must specify the left-hand boundary, :math:`a`, and :math:`\mathrm{x}[\textit{npts}-1]` must specify the right-hand boundary, :math:`b`. **nv** : int The number of coupled ODE components. **xi** : float, array-like, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`, must be set to the ODE/PDE coupling points. **rtol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 2)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (3, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The relative local error tolerance. **atol** : float, array-like, shape :math:`\left(:\right)` Note: the required length for this argument is determined as follows: if :math:`\mathrm{itol}\text{ in } (1, 3)`: :math:`1`; if :math:`\mathrm{itol}\text{ in } (2, 4)`: :math:`\textit{neqn}`; otherwise: :math:`0`. The absolute local error tolerance. **itol** : int A value to indicate the form of the local error test. If :math:`e_{\textit{i}}` is the estimated local error for :math:`\mathrm{u}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{neqn}`, and :math:`\left\lVert \quad \text{ }\quad \right\rVert`, denotes the norm, the error test to be satisfied is :math:`\left\lVert e_{\textit{i}}\right\rVert < 1.0`. :math:`\mathrm{itol}` indicates to ``dim1_parab_convdiff_remesh`` whether to interpret either or both of :math:`\mathrm{rtol}` and :math:`\mathrm{atol}` as a vector or scalar in the formation of the weights :math:`w_{\textit{i}}` used in the calculation of the norm (see the description of :math:`\mathrm{norm}`): +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |:math:`\mathrm{itol}`|:math:`\mathrm{rtol}`|:math:`\mathrm{atol}`|:math:`w_{\textit{i}}` | +=====================+=====================+=====================+=======================================================================================================================+ |1 |scalar |scalar |:math:`\mathrm{rtol}[0]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |2 |scalar |vector |:math:`\mathrm{rtol}[0]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[\textit{i}-1]` | +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |3 |vector |scalar |:math:`\mathrm{rtol}[\textit{i}-1]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[0]` | +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ |4 |vector |vector |:math:`\mathrm{rtol}[\textit{i}-1]\times \left\lvert \mathrm{u}[\textit{i}-1]\right\rvert +\mathrm{atol}[\textit{i}-1]`| +---------------------+---------------------+---------------------+-----------------------------------------------------------------------------------------------------------------------+ **norm** : str, length 1 The type of norm to be used. :math:`\mathrm{norm} = \texttt{'1'}` Averaged :math:`L_1` norm. :math:`\mathrm{norm} = \texttt{'2'}` Averaged :math:`L_2` norm. If :math:`U_{\mathrm{norm}}` denotes the norm of the vector :math:`\mathrm{u}` of length :math:`\textit{neqn}`, then for the averaged :math:`L_1` norm .. math:: U_{\mathrm{norm}} = \frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\mathrm{u}[i-1]/w_i\text{,} and for the averaged :math:`L_2` norm .. math:: U_{\mathrm{norm}} = \sqrt{\frac{1}{\textit{neqn}}\sum_{{i = 1}}^{\textit{neqn}}\left(\mathrm{u}[i-1]/w_i\right)^2}\text{,} See the description of :math:`\mathrm{itol}` for the formulation of the weight vector :math:`w`. **laopt** : str, length 1 The type of matrix algebra required. :math:`\mathrm{laopt} = \texttt{'F'}` Full matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'B'}` Banded matrix methods to be used. :math:`\mathrm{laopt} = \texttt{'S'}` Sparse matrix methods to be used. Note: you are recommended to use the banded option when no coupled ODEs are present (:math:`\mathrm{nv} = 0`). Also, the banded option should not be used if the boundary conditions involve solution components at points other than the boundary and the immediately adjacent two points. **algopt** : float, array-like, shape :math:`\left(30\right)` May be set to control various options available in the integrator. If you wish to employ all the default options, :math:`\mathrm{algopt}[0]` should be set to :math:`0.0`. Default values will also be used for any other elements of :math:`\mathrm{algopt}` set to zero. The permissible values, default values, and meanings are as follows: :math:`\mathrm{algopt}[0]` Selects the ODE integration method to be used. If :math:`\mathrm{algopt}[0] = 1.0`, a BDF method is used and if :math:`\mathrm{algopt}[0] = 2.0`, a Theta method is used. The default is :math:`\mathrm{algopt}[0] = 1.0`. If :math:`\mathrm{algopt}[0] = 2.0`, then :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4`, are not used. :math:`\mathrm{algopt}[1]` Specifies the maximum order of the BDF integration formula to be used. :math:`\mathrm{algopt}[1]` may be :math:`1.0`, :math:`2.0`, :math:`3.0`, :math:`4.0` or :math:`5.0`. The default value is :math:`\mathrm{algopt}[1] = 5.0`. :math:`\mathrm{algopt}[2]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the BDF method. If :math:`\mathrm{algopt}[2] = 1.0` a modified Newton iteration is used and if :math:`\mathrm{algopt}[2] = 2.0` a functional iteration method is used. If functional iteration is selected and the integrator encounters difficulty, there is an automatic switch to the modified Newton iteration. The default value is :math:`\mathrm{algopt}[2] = 1.0`. :math:`\mathrm{algopt}[3]` Specifies whether or not the Petzold error test is to be employed. The Petzold error test results in extra overhead but is more suitable when algebraic equations are present, such as :math:`P_{{i,\textit{j}}} = 0.0`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for some :math:`i` or when there is no :math:`\dot{V}_i\left(t\right)` dependence in the coupled ODE system. If :math:`\mathrm{algopt}[3] = 1.0`, the Petzold test is used. If :math:`\mathrm{algopt}[3] = 2.0`, the Petzold test is not used. The default value is :math:`\mathrm{algopt}[3] = 1.0`. If :math:`\mathrm{algopt}[0] = 1.0`, :math:`\mathrm{algopt}[\textit{i}-1]`, for :math:`\textit{i} = 5,6,\ldots,7`, are not used. :math:`\mathrm{algopt}[4]` Specifies the value of Theta to be used in the Theta integration method. :math:`0.51\leq \mathrm{algopt}[4]\leq 0.99`. The default value is :math:`\mathrm{algopt}[4] = 0.55`. :math:`\mathrm{algopt}[5]` Specifies what method is to be used to solve the system of nonlinear equations arising on each step of the Theta method. If :math:`\mathrm{algopt}[5] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[5] = 2.0`, a functional iteration method is used. The default value is :math:`\mathrm{algopt}[5] = 1.0`. :math:`\mathrm{algopt}[6]` Specifies whether or not the integrator is allowed to switch automatically between modified Newton and functional iteration methods in order to be more efficient. If :math:`\mathrm{algopt}[6] = 1.0`, switching is allowed and if :math:`\mathrm{algopt}[6] = 2.0`, switching is not allowed. The default value is :math:`\mathrm{algopt}[6] = 1.0`. :math:`\mathrm{algopt}[10]` Specifies a point in the time direction, :math:`t_{\mathrm{crit}}`, beyond which integration must not be attempted. The use of :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{itask}`. If :math:`\mathrm{algopt}[0]\neq 0.0`, a value of :math:`0.0` for :math:`\mathrm{algopt}[10]`, say, should be specified even if :math:`\mathrm{itask}` subsequently specifies that :math:`t_{\mathrm{crit}}` will not be used. :math:`\mathrm{algopt}[11]` Specifies the minimum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[11]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[12]` Specifies the maximum absolute step size to be allowed in the time integration. If this option is not required, :math:`\mathrm{algopt}[12]` should be set to :math:`0.0`. :math:`\mathrm{algopt}[13]` Specifies the initial step size to be attempted by the integrator. If :math:`\mathrm{algopt}[13] = 0.0`, the initial step size is calculated internally. :math:`\mathrm{algopt}[14]` Specifies the maximum number of steps to be attempted by the integrator in any one call. If :math:`\mathrm{algopt}[14] = 0.0`, no limit is imposed. :math:`\mathrm{algopt}[22]` Specifies what method is to be used to solve the nonlinear equations at the initial point to initialize the values of :math:`U`, :math:`U_t`, :math:`V` and :math:`\dot{V}`. If :math:`\mathrm{algopt}[22] = 1.0`, a modified Newton iteration is used and if :math:`\mathrm{algopt}[22] = 2.0`, functional iteration is used. The default value is :math:`\mathrm{algopt}[22] = 1.0`. :math:`\mathrm{algopt}[28]` and :math:`\mathrm{algopt}[29]` are used only for the sparse matrix algebra option, i.e., :math:`\mathrm{laopt} = \texttt{'S'}`. :math:`\mathrm{algopt}[28]` Governs the choice of pivots during the decomposition of the first Jacobian matrix. It should lie in the range :math:`0.0 < \mathrm{algopt}[28] < 1.0`, with smaller values biasing the algorithm towards maintaining sparsity at the expense of numerical stability. If :math:`\mathrm{algopt}[28]` lies outside the range then the default value is used. If the functions regard the Jacobian matrix as numerically singular, increasing :math:`\mathrm{algopt}[28]` towards :math:`1.0` may help, but at the cost of increased fill-in. The default value is :math:`\mathrm{algopt}[28] = 0.1`. :math:`\mathrm{algopt}[29]` Used as the relative pivot threshold during subsequent Jacobian decompositions (see :math:`\mathrm{algopt}[28]`) below which an internal error is invoked. :math:`\mathrm{algopt}[29]` must be greater than zero, otherwise the default value is used. If :math:`\mathrm{algopt}[29]` is greater than :math:`1.0` no check is made on the pivot size, and this may be a necessary option if the Jacobian matrix is found to be numerically singular (see :math:`\mathrm{algopt}[28]`). The default value is :math:`\mathrm{algopt}[29] = 0.0001`. **remesh** : bool Indicates whether or not spatial remeshing should be performed. :math:`\mathrm{remesh} = \mathbf{True}` Indicates that spatial remeshing should be performed as specified. :math:`\mathrm{remesh} = \mathbf{False}` Indicates that spatial remeshing should be suppressed. Note: :math:`\mathrm{remesh}` should **not** be changed between consecutive calls to ``dim1_parab_convdiff_remesh``. Remeshing can be switched off or on at specified times by using appropriate values for the arguments :math:`\mathrm{nrmesh}` and :math:`\mathrm{trmesh}` at each call. **xfix** : float, array-like, shape :math:`\left(\textit{nxfix}\right)` :math:`\mathrm{xfix}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxfix}`, must contain the value of the :math:`x` coordinate at the :math:`\textit{i}`\ th fixed mesh point. **nrmesh** : int Specifies the spatial remeshing frequency and criteria for the calculation and adoption of a new mesh. :math:`\mathrm{nrmesh} < 0` Indicates that a new mesh is adopted according to the argument :math:`\mathrm{dxmesh}`. The mesh is tested every :math:`\left\lvert \mathrm{nrmesh}\right\rvert` timesteps. :math:`\mathrm{nrmesh} = 0` Indicates that remeshing should take place just once at the end of the first time step reached when :math:`t > \mathrm{trmesh}`. :math:`\mathrm{nrmesh} > 0` Indicates that remeshing will take place every :math:`\mathrm{nrmesh}` time steps, with no testing using :math:`\mathrm{dxmesh}`. Note: :math:`\mathrm{nrmesh}` may be changed between consecutive calls to ``dim1_parab_convdiff_remesh`` to give greater flexibility over the times of remeshing. **dxmesh** : float Determines whether a new mesh is adopted when :math:`\mathrm{nrmesh}` is set less than zero. A possible new mesh is calculated at the end of every :math:`\left\lvert \mathrm{nrmesh}\right\rvert` time steps, but is adopted only if .. math:: x_i^{\mathrm{new}} > x_i^{\mathrm{old}}+\mathrm{dxmesh}\times \left(x_{{i+1}}^{\mathrm{old}}-x_i^{\mathrm{old}}\right) or .. math:: x_i^{\mathrm{new}} < x_i^{\mathrm{old}}-\mathrm{dxmesh}\times \left(x_i^{\mathrm{old}}-x_{{i-1}}^{\mathrm{old}}\right) :math:`\mathrm{dxmesh}` thus imposes a lower limit on the difference between one mesh and the next. **trmesh** : float Specifies when remeshing will take place when :math:`\mathrm{nrmesh}` is set to zero. Remeshing will occur just once at the end of the first time step reached when :math:`t` is greater than :math:`\mathrm{trmesh}`. Note: :math:`\mathrm{trmesh}` may be changed between consecutive calls to ``dim1_parab_convdiff_remesh`` to force remeshing at several specified times. **ipminf** : int The level of trace information regarding the adaptive remeshing. Details are directed to the file object associated with the advisory I/O unit (see :class:`~naginterfaces.base.utils.FileObjManager`). :math:`\mathrm{ipminf} = 0` No trace information. :math:`\mathrm{ipminf} = 1` Brief summary of mesh characteristics. :math:`\mathrm{ipminf} = 2` More detailed information, including old and new mesh points, mesh sizes and monitor function values. **comm** : dict, communication object, modified in place Note: this argument will be (re-)initialized when it is an empty ``dict`` or under the following condition: :math:`\mathrm{ind} = 0`. Communication structure. `On initial entry`: need not be set. **itask** : int The task to be performed by the ODE integrator. :math:`\mathrm{itask} = 1` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` (by overshooting and interpolating). :math:`\mathrm{itask} = 2` Take one step in the time direction and return. :math:`\mathrm{itask} = 3` Stop at first internal integration point at or beyond :math:`t = \mathrm{tout}`. :math:`\mathrm{itask} = 4` Normal computation of output values :math:`\mathrm{u}` at :math:`t = \mathrm{tout}` but without overshooting :math:`t = t_{\mathrm{crit}}` where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. :math:`\mathrm{itask} = 5` Take one step in the time direction and return, without passing :math:`t_{\mathrm{crit}}`, where :math:`t_{\mathrm{crit}}` is described under the argument :math:`\mathrm{algopt}`. **itrace** : int The level of trace information required from ``dim1_parab_convdiff_remesh`` and the underlying ODE solver. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages from the PDE solver are printed. :math:`\mathrm{itrace} > 0` Output from the underlying ODE solver is printed. This output contains details of Jacobian entries, the nonlinear iteration and the time integration during the computation of the ODE system. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. You are advised to set :math:`\mathrm{itrace} = 0`, unless you are experienced with submodule :mod:`~naginterfaces.library.ode`. **ind** : int Indicates whether this is a continuation call or a new integration. :math:`\mathrm{ind} = 0` Starts or restarts the integration in time. :math:`\mathrm{ind} = 1` Continues the integration after an earlier exit from the function. In this case, only the arguments :math:`\mathrm{tout}`, :math:`\mathrm{nrmesh}` and :math:`\mathrm{trmesh}` may be reset between calls to ``dim1_parab_convdiff_remesh``. **pdedef** : None or callable (p, c, d, s, ires) = pdedef(t, x, u, ux, v, vdot, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{pdedef}` must evaluate the functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` which partially define the system of PDEs. :math:`P_{{i,j}}` and :math:`C_i` may depend on :math:`x`, :math:`t`, :math:`U` and :math:`V`; :math:`D_i` may depend on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`; and :math:`S_i` may depend on :math:`x`, :math:`t`, :math:`U`, :math:`V` and linearly on :math:`\dot{V}`. :math:`\mathrm{pdedef}` is called approximately midway between each pair of mesh points in turn by ``dim1_parab_convdiff_remesh``. **None** may be used for :math:`\mathrm{pdedef}` for problems in the form `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn2>`__. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float The current value of the space variable :math:`x`. **u** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1]` contains the value of the component :math:`U_{\textit{i}}\left(x, t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ux** : float, ndarray, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1]` contains the value of the component :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. Note: :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, may only appear linearly in :math:`S_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Set to :math:`-1` or :math:`1`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **p** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npde}\right)` :math:`\mathrm{p}[\textit{i}-1,\textit{j}-1]` must be set to the value of :math:`P_{{\textit{i},\textit{j}}}\left(x, t, U, V\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **c** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{c}[\textit{i}-1]` must be set to the value of :math:`C_{\textit{i}}\left(x, t, U, V\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **d** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{d}[\textit{i}-1]` must be set to the value of :math:`D_{\textit{i}}\left(x, t, U, U_x, V\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **s** : float, array-like, shape :math:`\left(\textit{npde}\right)` :math:`\mathrm{s}[\textit{i}-1]` must be set to the value of :math:`S_{\textit{i}}\left(x, t, U, V, {\dot{V}}\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int Should usually remain unchanged. However, you may set :math:`\mathrm{ires}` to force the integration function to take certain actions as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_remesh`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **odedef** : None or callable (r, ires) = odedef(t, v, vdot, xi, ucp, ucpx, ucpt, ires, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{odedef}` must evaluate the functions :math:`R`, which define the system of ODEs, as given in `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn4>`__. If you wish to compute the solution of a system of PDEs only (i.e., :math:`\mathrm{nv} = 0`), :math:`\mathrm{odedef}` must be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **v** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{v}[\textit{i}-1]` contains the value of the component :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **vdot** : float, ndarray, shape :math:`\left(\textit{nv}\right)` If :math:`\mathrm{nv} > 0`, :math:`\mathrm{vdot}[\textit{i}-1]` contains the value of component :math:`\dot{V}_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **xi** : float, ndarray, shape :math:`\left(\textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{xi}[\textit{i}-1]` contains the ODE/PDE coupling point, :math:`\xi_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{nxi}`. **ucp** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucp}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpx** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}\left(x, t\right)}}{{\partial x}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ucpt** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{nxi}\right)` If :math:`\textit{nxi} > 0`, :math:`\mathrm{ucpt}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial U_{\textit{i}}}}{{\partial t}}` at the coupling point :math:`x = \xi_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\textit{nxi}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **ires** : int The form of :math:`R` that must be returned in the array :math:`\mathrm{r}`. :math:`\mathrm{ires} = 1` Equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn11>`__ must be used. :math:`\mathrm{ires} = -1` Equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn12>`__ must be used. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **r** : float, array-like, shape :math:`\left(\textit{nv}\right)` :math:`\mathrm{r}[\textit{i}-1]` must contain the :math:`\textit{i}`\ th component of :math:`R`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`, where :math:`R` is defined as .. math:: R = L-M\dot{V}-NU_t^*\text{,} or .. math:: R = -M\dot{V}-NU_t^*\text{.} The definition of :math:`R` is determined by the input value of :math:`\mathrm{ires}`. **ires** : int Should usually remain unchanged. However, you may reset :math:`\mathrm{ires}` to force the integration function to take certain actions, as described below: :math:`\mathrm{ires} = 2` Indicates to the integrator that control should be passed back immediately to the calling function with the error indicator set to :math:`\mathrm{errno}` = 6. :math:`\mathrm{ires} = 3` Indicates to the integrator that the current time step should be abandoned and a smaller time step used instead. You may wish to set :math:`\mathrm{ires} = 3` when a physically meaningless input or output value has been generated. If you consecutively set :math:`\mathrm{ires} = 3`, ``dim1_parab_convdiff_remesh`` returns to the calling function with the error indicator set to :math:`\mathrm{errno}` = 4. **xratio** : float, optional An input bound on the adjacent mesh ratio (greater than :math:`1.0` and typically in the range :math:`1.5` to :math:`3.0`). The remeshing functions will attempt to ensure that .. math:: \left(x_i-x_{{i-1}}\right)/\mathrm{xratio} < x_{{i+1}}-x_i < \mathrm{xratio}\times \left(x_i-x_{{i-1}}\right)\text{.} **con** : None or float, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`2.0/\left(\textit{npts}-1\right)`. An input bound on the sub-integral of the monitor function :math:`F^{\mathrm{mon}}\left(x\right)` over each space step. The remeshing functions will attempt to ensure that .. math:: \int_{x_i}^{x_{{i+1}}}F^{\mathrm{mon}}\left(x\right){dx}\leq \mathrm{con}\int_{x_1}^{x_{\textit{npts}}}F^{\mathrm{mon}}\left(x\right){dx}\text{,} (see Furzeland (1984)). :math:`\mathrm{con}` gives you more control over the mesh distribution, e.g., decreasing :math:`\mathrm{con}` allows more clustering. A typical value is :math:`2.0/\left(\textit{npts}-1\right)`, but you are encouraged to experiment with different values. Its value is not critical and the mesh should be qualitatively correct for all values in the range given below. **monitf** : None or callable fmon = monitf(t, x, u, data=None), optional Note: if this argument is **None** then a NAG-supplied facility will be used. :math:`\mathrm{monitf}` must supply and evaluate a remesh monitor function to indicate the solution behaviour of interest. If you specify :math:`\mathrm{remesh} = \mathbf{False}`, i.e., no remeshing, :math:`\mathrm{monitf}` will not be called and may be **None**. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The current mesh. :math:`\mathrm{x}[\textit{i}-1]` contains the value of :math:`x_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{npts}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`U_{\textit{i}}\left(x, t\right)` at :math:`x = \mathrm{x}[\textit{j}-1]` and time :math:`t`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **fmon** : float, array-like, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{fmon}[i-1]` must contain the value of the monitor function :math:`F^{\mathrm{mon}}\left(x\right)` at mesh point :math:`x = \mathrm{x}[i-1]`. **lrsave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['rsave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lrsave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lrsave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lrsave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lrsave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lrsave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **lisave_estim** : int, optional When performing a new integration, the size to use for the communication array :math:`\mathrm{comm}`\ ['isave']. Otherwise, the value has no effect. An initial estimate for an adequate :math:`\mathrm{lisave\_estim}` is computed by the function. If your supplied :math:`\mathrm{lisave\_estim}` is too small, the estimated value will be used instead. In some cases the estimated value will be sufficient for continuation calls to the function. When :math:`\mathrm{laopt} = \texttt{'S'}`, even the function's initial estimated value of :math:`\mathrm{lisave\_estim}` may be too small. If so, the function returns with :math:`\mathrm{errno}` = 15. You are advised to call the function again with :math:`\mathrm{ind} = 0` and :math:`\mathrm{lisave\_estim}` set to at least the lower-bound value returned in :math:`\mathrm{lisave\_min}`, then make the desired subsequent calls with :math:`\mathrm{ind} = 1`, then repeat the process if necessary. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{p}` in :math:`\mathrm{pdedef}` or :math:`\mathrm{u}` in :math:`\mathrm{uvinit}` are spiked (i.e., have unit extent in all but one dimension, or have size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with them in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. **Returns** **ts** : float The value of :math:`t` corresponding to the solution values in :math:`\mathrm{u}`. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **u** : float, ndarray, shape :math:`\left(\textit{neqn}\right)` The computed solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`V_{\textit{k}}\left(t\right)`, for :math:`\textit{k} = 1,2,\ldots,\mathrm{nv}`, evaluated at :math:`t = \mathrm{ts}`, as follows: :math:`\mathrm{u}[\mathrm{npde}\times \left(\textit{j}-1\right)+\textit{i}-1]` contain :math:`U_{\textit{i}}\left(x_{\textit{j}}, t\right)`, for :math:`\textit{j} = 1,2,\ldots,\textit{npts}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, and :math:`\mathrm{u}[\textit{npts}\times \mathrm{npde}+\textit{i}-1]` contain :math:`V_{\textit{i}}\left(t\right)`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nv}`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` The final values of the mesh points. **ind** : int :math:`\mathrm{ind} = 1`. **lrsave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['rsave']. **lisave_min** : int A lower bound on the sufficient size for :math:`\mathrm{comm}`\ ['isave']. .. _d03ps-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, on initial entry :math:`\mathrm{ind} = 1`. Constraint: on initial entry :math:`\mathrm{ind} = 0`. (`errno` :math:`1`) On entry, the point :math:`\mathrm{xfix}[\textit{i}-1]` does not coincide with any :math:`\mathrm{x}[\textit{j}-1]`: :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xfix}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xfix}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xfix}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xfix}[\textit{i}] > \mathrm{xfix}[\textit{i}-1]`. (`errno` :math:`1`) On entry, at least one point in :math:`\mathrm{xi}` lies outside :math:`\left[{\mathrm{x}[0]}, {\mathrm{x}[\textit{npts}-1]}\right]`: :math:`\mathrm{x}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{npts}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xi}[\textit{i}] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xi}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xi}[\textit{i}] > \mathrm{xi}[\textit{i}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: corresponding elements :math:`\mathrm{atol}[\textit{i}-1]` and :math:`\mathrm{rtol}[\textit{j}-1]` cannot both be :math:`0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{rtol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{rtol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{atol}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{atol}[\textit{i}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{itol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itol} = 1`, :math:`2`, :math:`3` or :math:`4`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{neqn} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{neqn} = \mathrm{npde}\times \textit{npts}+\mathrm{nv}`. (`errno` :math:`1`) On entry, :math:`\mathrm{con} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{con}\leq 10.0/\left(\textit{npts}-1\right)`. (`errno` :math:`1`) On entry, :math:`\mathrm{con} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{con}\geq 0.1/\left(\textit{npts}-1\right)`. (`errno` :math:`1`) On entry, :math:`\mathrm{xratio} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xratio} > 1.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{ipminf} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ipminf} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{dxmesh} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dxmesh}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{nxfix} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxfix}\leq \textit{npts}-2`. (`errno` :math:`1`) On entry, :math:`\textit{nxfix} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxfix}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi} = 0` when :math:`\mathrm{nv} = 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nxi} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nxi}\geq 0` when :math:`\mathrm{nv} > 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts}\geq 3`. (`errno` :math:`1`) On entry, :math:`\mathrm{laopt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{laopt} = \texttt{'F'}`, :math:`\texttt{'B'}` or :math:`\texttt{'S'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{norm} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{norm} = \texttt{'1'}` or :math:`\texttt{'2'}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ind} = 0` or :math:`1`. (`errno` :math:`1`) On entry, :math:`\mathrm{itask} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itask} = 1`, :math:`2`, :math:`3`, :math:`4` or :math:`5`. (`errno` :math:`1`) On entry, :math:`\mathrm{nv} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nv}\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` is too small: :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`4`) In setting up the ODE system an internal auxiliary was unable to initialize the derivative. This could be due to your setting :math:`\mathrm{ires} = 3` in :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, :math:`\mathrm{bndary}` or :math:`\mathrm{odedef}`. (`errno` :math:`5`) Singular Jacobian of ODE system. Check problem formulation. (`errno` :math:`7`) :math:`\mathrm{atol}` and :math:`\mathrm{rtol}` were too small to start integration. (`errno` :math:`8`) :math:`\mathrm{ires}` set to an invalid value in a call to functions :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, :math:`\mathrm{bndary}` or :math:`\mathrm{odedef}`. (`errno` :math:`9`) Serious error in internal call to an auxiliary. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`11`) Error during Jacobian formulation for ODE system. Increase :math:`\mathrm{itrace}` for further details. (`errno` :math:`12`) In solving ODE system, the maximum number of steps :math:`\mathrm{algopt}[14]` has been exceeded. :math:`\mathrm{algopt}[14] = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`14`) The functions :math:`P`, :math:`D`, or :math:`C` appear to depend on time derivatives. (`errno` :math:`16`) :math:`\mathrm{remesh}` has been changed between calls to ``dim1_parab_convdiff_remesh``. (`errno` :math:`17`) :math:`\mathrm{fmon}` is negative at one or more mesh points, or zero mesh spacing has been obtained due to a poor monitor function. **Warns** **NagAlgorithmicWarning** (`errno` :math:`2`) Underlying ODE solver cannot make further progress from the point :math:`\mathrm{ts}` with the supplied values of :math:`\mathrm{atol}` and :math:`\mathrm{rtol}`. :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`3`) Repeated errors in an attempted step of underlying ODE solver. Integration was successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`6`) In evaluating residual of ODE system, :math:`\mathrm{ires} = 2` has been set in functions :math:`\mathrm{pdedef}`, :math:`\mathrm{numflx}`, :math:`\mathrm{bndary}` or :math:`\mathrm{odedef}`. Integration is successful as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`10`) Integration completed, but small changes in :math:`\mathrm{atol}` or :math:`\mathrm{rtol}` are unlikely to result in a changed solution. (`errno` :math:`13`) Zero error weights encountered during time integration. (`errno` :math:`15`) When using the sparse option, :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right)` or :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right)` is too small: :math:`\mathrm{max}\left(\mathrm{lisave\_min}, \mathrm{lisave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{max}\left(\mathrm{lrsave\_min}, \mathrm{lrsave\_estim}\right) = \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03ps-py2-py-notes: **Notes** ``dim1_parab_convdiff_remesh`` integrates the system of convection-diffusion equations in conservative form: .. math:: \sum_{{j = 1}}^{\mathrm{npde}}P_{{i,j}}\frac{{\partial U_j}}{{\partial t}}+\frac{{\partial F_i}}{{\partial x}} = C_i\frac{{\partial D_i}}{{\partial x}}+S_i\text{,} or the hyperbolic convection-only system: .. math:: \frac{{\partial U_i}}{{\partial t}}+\frac{{\partial F_i}}{{\partial x}} = 0\text{,} for :math:`i = 1,2,\ldots,\mathrm{npde}`, :math:`a\leq x\leq b`, :math:`t\geq t_0`, where the vector :math:`U` is the set of PDE solution values .. math:: U\left(x, t\right) = {\left[{U_1\left(x, t\right)}, \ldots, {U_{\mathrm{npde}}\left(x, t\right)}\right]}^{\mathrm{T}}\text{.} The optional coupled ODEs are of the general form .. math:: R_i\left(t, V, {\dot{V}}, \xi, U^*, {U_x^*}, {U_t^*}\right) = 0\text{, }\quad i = 1,2,\ldots,\mathrm{nv}\text{,} where the vector :math:`V` is the set of ODE solution values .. math:: V\left(t\right) = {\left[{V_1\left(t\right)}, \ldots, {V_{\mathrm{nv}}\left(t\right)}\right]}^{\mathrm{T}}\text{,} :math:`\dot{V}` denotes its derivative with respect to time, and :math:`U_x` is the spatial derivative of :math:`U`. In `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn2>`__, :math:`P_{{i,j}}`, :math:`F_i` and :math:`C_i` depend on :math:`x`, :math:`t`, :math:`U` and :math:`V`; :math:`D_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`U_x` and :math:`V`; and :math:`S_i` depends on :math:`x`, :math:`t`, :math:`U`, :math:`V` and **linearly** on :math:`\dot{V}`. Note that :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` must not depend on any space derivatives, and :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`D_i` must not depend on any time derivatives. In terms of conservation laws, :math:`F_i`, :math:`\frac{{C_i\partial D_i}}{{\partial x}}` and :math:`S_i` are the convective flux, diffusion and source terms respectively. In `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn3>`__, :math:`\xi` represents a vector of :math:`n_{\xi }` spatial coupling points at which the ODEs are coupled to the PDEs. These points may or may not be equal to PDE spatial mesh points. :math:`U^*`, :math:`U_x^*` and :math:`U_t^*` are the functions :math:`U`, :math:`U_x` and :math:`U_t` evaluated at these coupling points. Each :math:`R_i` may depend only linearly on time derivatives. Hence `(3) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn3>`__ may be written more precisely as .. math:: R = L-M\dot{V}-NU_t^*\text{,} where :math:`R = \left[R_1, \ldots, R_{\mathrm{nv}}\right]^\mathrm{T}`, :math:`L` is a vector of length :math:`\mathrm{nv}`, :math:`M` is an :math:`\mathrm{nv}` by :math:`\mathrm{nv}` matrix, :math:`N` is an :math:`\mathrm{nv}` by :math:`\left(n_{\xi }\times \mathrm{npde}\right)` matrix and the entries in :math:`L`, :math:`M` and :math:`N` may depend on :math:`t`, :math:`\xi`, :math:`U^*`, :math:`U_x^*` and :math:`V`. In practice you only need to supply a vector of information to define the ODEs and not the matrices :math:`L`, :math:`M` and :math:`N`. (See :ref:`Parameters <d03ps-py2-py-parameters>` for the specification of :math:`\mathrm{odedef}`.) The integration in time is from :math:`t_0` to :math:`t_{\mathrm{out}}`, over the space interval :math:`a\leq x\leq b`, where :math:`a = x_1` and :math:`b = x_{\textit{npts}}` are the leftmost and rightmost points of a user-defined mesh :math:`x_1,x_2,\ldots,x_{\textit{npts}}` defined initially by you and (possibly) adapted automatically during the integration according to user-specified criteria. The initial :math:`\left(t = t_0\right)` values of the functions :math:`U\left(x, t\right)` and :math:`V\left(t\right)` must be specified in :math:`\mathrm{uvinit}`. Note that :math:`\mathrm{uvinit}` will be called again following any initial remeshing, and so :math:`U\left(x, t_0\right)` should be specified for **all** values of :math:`x` in the interval :math:`a\leq x\leq b`, and not just the initial mesh points. The PDEs are approximated by a system of ODEs in time for the values of :math:`U_i` at mesh points using a spatial discretization method similar to the central-difference scheme used in :meth:`dim1_parab_fd`, :meth:`dim1_parab_dae_fd` and :meth:`dim1_parab_remesh_fd`, but with the flux :math:`F_i` replaced by a `numerical flux`, which is a representation of the flux taking into account the direction of the flow of information at that point (i.e., the direction of the characteristics). Simple central differencing of the numerical flux then becomes a sophisticated upwind scheme in which the correct direction of upwinding is automatically achieved. The numerical flux, :math:`\hat{F}_i` say, must be calculated by you in terms of the `left` and `right` values of the solution vector :math:`U` (denoted by :math:`U_L` and :math:`U_R` respectively), at each mid-point of the mesh :math:`x_{{\textit{j}-\frac{1}{2}}} = \left(x_{{\textit{j}-1}}+x_{\textit{j}}\right)/2`, for :math:`\textit{j} = 2,3,\ldots,\textit{npts}`. The left and right values are calculated by ``dim1_parab_convdiff_remesh`` from two adjacent mesh points using a standard upwind technique combined with a Van Leer slope-limiter (see LeVeque (1990)). The physically correct value for :math:`\hat{F}_i` is derived from the solution of the Riemann problem given by .. math:: \frac{{\partial U_i}}{{\partial t}}+\frac{{\partial F_i}}{{\partial y}} = 0\text{,} where :math:`y = x-x_{{j-\frac{1}{2}}}`, i.e., :math:`y = 0` corresponds to :math:`x = x_{{j-\frac{1}{2}}}`, with discontinuous initial values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`, using an `approximate Riemann solver`. This applies for either of the systems `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn1>`__ and `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn1>`__; the numerical flux is independent of the functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i`. A description of several approximate Riemann solvers can be found in LeVeque (1990) and Berzins `et al.` (1989). Roe's scheme (see Roe (1981)) is perhaps the easiest to understand and use, and a brief summary follows. Consider the system of PDEs :math:`U_t+F_x = 0` or equivalently :math:`U_t+AU_x = 0`. Provided the system is linear in :math:`U`, i.e., the Jacobian matrix :math:`A` does not depend on :math:`U`, the numerical flux :math:`\hat{F}` is given by .. math:: \hat{F} = \frac{1}{2}\left(F_L+F_R\right)-\frac{1}{2}\sum_{{k = 1}}^{\mathrm{npde}}\alpha_k\left\lvert \lambda_k\right\rvert e_k\text{,} where :math:`F_L` (:math:`F_R`) is the flux :math:`F` calculated at the left (right) value of :math:`U`, denoted by :math:`U_L` (:math:`U_R`); the :math:`\lambda_k` are the eigenvalues of :math:`A`; the :math:`e_k` are the right eigenvectors of :math:`A`; and the :math:`\alpha_k` are defined by .. math:: U_R-U_L = \sum_{{k = 1}}^{\mathrm{npde}}\alpha_ke_k\text{.} Examples are given in the documents for :meth:`dim1_parab_convdiff` and :meth:`dim1_parab_convdiff_dae`. If the system is nonlinear, Roe's scheme requires that a linearized Jacobian is found (see Roe (1981)). The functions :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` (but **not** :math:`F_i`) must be specified in :math:`\mathrm{pdedef}`. The numerical flux :math:`\hat{F}_i` must be supplied in :math:`\mathrm{numflx}`. For problems in the form `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn2>`__, **None** may be used for :math:`\mathrm{pdedef}`. This sets the matrix with entries :math:`P_{{i,j}}` to the identity matrix, and the functions :math:`C_i`, :math:`D_i` and :math:`S_i` to zero. For second-order problems, i.e., diffusion terms are present, a boundary condition is required for each PDE at both boundaries for the problem to be well-posed. If there are no diffusion terms present, then the continuous PDE problem generally requires exactly one boundary condition for each PDE, that is :math:`\mathrm{npde}` boundary conditions in total. However, in common with most discretization schemes for first-order problems, a `numerical boundary condition` is required at the other boundary for each PDE. In order to be consistent with the characteristic directions of the PDE system, the numerical boundary conditions must be derived from the solution inside the domain in some manner (see below). You must supply both types of boundary conditions, i.e., a total of :math:`\mathrm{npde}` conditions at each boundary point. The position of each boundary condition should be chosen with care. In simple terms, if information is flowing into the domain then a physical boundary condition is required at that boundary, and a numerical boundary condition is required at the other boundary. In many cases the boundary conditions are simple, e.g., for the linear advection equation. In general you should calculate the characteristics of the PDE system and specify a physical boundary condition for each of the characteristic variables associated with incoming characteristics, and a numerical boundary condition for each outgoing characteristic. A common way of providing numerical boundary conditions is to extrapolate the characteristic variables from the inside of the domain (note that when using banded matrix algebra the fixed bandwidth means that only linear extrapolation is allowed, i.e., using information at just two interior points adjacent to the boundary). For problems in which the solution is known to be uniform (in space) towards a boundary during the period of integration then extrapolation is unnecessary; the numerical boundary condition can be supplied as the known solution at the boundary. Another method of supplying numerical boundary conditions involves the solution of the characteristic equations associated with the outgoing characteristics. Examples of both methods can be found in the documents for :meth:`dim1_parab_convdiff` and :meth:`dim1_parab_convdiff_dae`. The boundary conditions must be specified in :math:`\mathrm{bndary}` in the form .. math:: G_i^L\left(x, t, U, V, {\dot{V}}\right) = 0\quad \text{ at }x = a\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} at the left-hand boundary, and .. math:: G_i^R\left(x, t, U, V, {\dot{V}}\right) = 0\quad \text{ at }x = b\text{, }\quad i = 1,2,\ldots,\mathrm{npde}\text{,} at the right-hand boundary. Note that spatial derivatives at the boundary are not passed explicitly to :math:`\mathrm{bndary}`, but they can be calculated using values of :math:`U` at and adjacent to the boundaries if required. However, it should be noted that instabilities may occur if such one-sided differencing opposes the characteristic direction at the boundary. The algebraic-differential equation system which is defined by the functions :math:`R_i` must be specified in :math:`\mathrm{odedef}`. You must also specify the coupling points :math:`\xi` (if any) in the array :math:`\mathrm{xi}`. In total there are :math:`\mathrm{npde}\times \textit{npts}+\mathrm{nv}` ODEs in the time direction. This system is then integrated forwards in time using a BDF or Theta method, optionally switching between Newton's method and functional iteration (see Berzins `et al.` (1989) and the references therein). The adaptive space remeshing can be used to generate meshes that automatically follow the changing time-dependent nature of the solution, generally resulting in a more efficient and accurate solution using fewer mesh points than may be necessary with a fixed uniform or non-uniform mesh. Problems with travelling wavefronts or variable-width boundary layers for example will benefit from using a moving adaptive mesh. The discrete time-step method used here (developed by Furzeland (1984)) automatically creates a new mesh based on the current solution profile at certain time-steps, and the solution is then interpolated onto the new mesh and the integration continues. The method requires you to supply a :math:`\mathrm{monitf}` which specifies in an analytical or numerical form the particular aspect of the solution behaviour you wish to track. This so-called monitor function is used by the function to choose a mesh which equally distributes the integral of the monitor function over the domain. A typical choice of monitor function is the second space derivative of the solution value at each point (or some combination of the second space derivatives if there is more than one solution component), which results in refinement in regions where the solution gradient is changing most rapidly. You must specify the frequency of mesh updates together with certain other criteria such as adjacent mesh ratios. Remeshing can be expensive and you are encouraged to experiment with the different options in order to achieve an efficient solution which adequately tracks the desired features of the solution. Note that unless the monitor function for the initial solution values is zero at all user-specified initial mesh points, a new initial mesh is calculated and adopted according to the user-specified remeshing criteria. :math:`\mathrm{uvinit}` will then be called again to determine the initial solution values at the new mesh points (there is no interpolation at this stage) and the integration proceeds. The problem is subject to the following restrictions: (i) In `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03psf.html#eqn1>`__, :math:`\dot{V}_{\textit{j}}\left(t\right)`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{nv}`, may only appear **linearly** in the functions :math:`S_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, with a similar restriction for :math:`G_i^L` and :math:`G_i^R`; (#) :math:`P_{{i,j}}`, :math:`F_i`, :math:`C_i` and :math:`S_i` must not depend on any space derivatives; and :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`F_i` must not depend on any time derivatives; (#) :math:`t_0 < t_{\mathrm{out}}`, so that integration is in the forward direction; (#) The evaluation of the terms :math:`P_{{i,j}}`, :math:`C_i`, :math:`D_i` and :math:`S_i` is done by calling the :math:`\mathrm{pdedef}` at a point approximately midway between each pair of mesh points in turn. Any discontinuities in these functions **must**, therefore, be at one or more of the **fixed** mesh points specified by :math:`\mathrm{xfix}`; (#) At least one of the functions :math:`P_{{i,j}}` must be nonzero so that there is a time derivative present in the PDE problem. For further details of the scheme, see Pennington and Berzins (1994) and the references therein. .. _d03ps-py2-py-references: **References** 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 Furzeland, R M, 1984, `The construction of adaptive space meshes`, TNER.85.022, Thornton Research Centre, Chester Hirsch, C, 1990, `Numerical Computation of Internal and External Flows, Volume 2: Computational Methods for Inviscid and Viscous Flows`, John Wiley LeVeque, R J, 1990, `Numerical Methods for Conservation Laws`, Birkhäuser Verlag Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 Roe, P L, 1981, `Approximate Riemann solvers, parameter vectors, and difference schemes`, J. Comput. Phys. (43), 357--372 """ raise NotImplementedError
[docs]def dim1_parab_euler_roe(uleft, uright, gamma, comm): r""" ``dim1_parab_euler_roe`` calculates a numerical flux function using Roe's Approximate Riemann Solver for the Euler equations in conservative form. It is designed primarily for use with the upwind discretization schemes :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` or :meth:`dim1_parab_convdiff_remesh`, but may also be applicable to other conservative upwind schemes requiring numerical flux functions. .. _d03pu-py2-py-doc: For full information please refer to the NAG Library document for d03pu https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03puf.html .. _d03pu-py2-py-parameters: **Parameters** **uleft** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uleft}[\textit{i}-1]` must contain the left value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uleft}[0]` must contain the left value of :math:`\rho`, :math:`\mathrm{uleft}[1]` must contain the left value of :math:`m` and :math:`\mathrm{uleft}[2]` must contain the left value of :math:`e`. **uright** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uright}[\textit{i}-1]` must contain the right value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uright}[0]` must contain the right value of :math:`\rho`, :math:`\mathrm{uright}[1]` must contain the right value of :math:`m` and :math:`\mathrm{uright}[2]` must contain the right value of :math:`e`. **gamma** : float The ratio of specific heats, :math:`\gamma`. **comm** : dict, communication object Communication structure. `On initial entry`: need not be set. **Returns** **flux** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{flux}[\textit{i}-1]` contains the numerical flux component :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. .. _d03pu-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{gamma} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{gamma} > 0.0`. (`errno` :math:`2`) Right pressure value :math:`\textit{pr} < 0.0`: :math:`\textit{pr} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) Left pressure value :math:`\textit{pl} < 0.0`: :math:`\textit{pl} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) On entry, :math:`\mathrm{uright}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uright}[0]\geq 0.0`. (`errno` :math:`2`) On entry, :math:`\mathrm{uleft}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uleft}[0]\geq 0.0`. .. _d03pu-py2-py-notes: **Notes** ``dim1_parab_euler_roe`` calculates a numerical flux function at a single spatial point using Roe's Approximate Riemann Solver (see Roe (1981)) for the Euler equations (for a perfect gas) in conservative form. You must supply the `left` and `right` solution values at the point where the numerical flux is required, i.e., the initial left and right states of the Riemann problem defined below. In the functions :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` and :meth:`dim1_parab_convdiff_remesh`, the left and right solution values are derived automatically from the solution values at adjacent spatial points and supplied to the function argument :math:`\textit{numflx}` from which you may call ``dim1_parab_euler_roe``. The Euler equations for a perfect gas in conservative form are: .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial x}} = 0\text{,} with .. math:: U = \left[\begin{array}{c}\rho \\m\\e\end{array}\right]\text{ and }F = \left[\begin{array}{c}m\\ \frac{m^2}{\rho } + \left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \\ \frac{{me}}{\rho } + \frac{m}{\rho } \left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \end{array}\right]\text{,} where :math:`\rho` is the density, :math:`m` is the momentum, :math:`e` is the specific total energy, and :math:`\gamma` is the (constant) ratio of specific heats. The pressure :math:`p` is given by .. math:: p = \left(\gamma -1\right)\left(e-\frac{{\rho u^2}}{2}\right)\text{,} where :math:`u = m/\rho` is the velocity. The function calculates the Roe approximation to the numerical flux function :math:`F\left(U_L, U_R\right) = F\left({U^*\left(U_L, U_R\right)}\right)`, where :math:`U = U_L` and :math:`U = U_R` are the left and right solution values, and :math:`U^*\left(U_L, U_R\right)` is the intermediate state :math:`\omega \left(0\right)` arising from the similarity solution :math:`U\left(y, t\right) = \omega \left(y/t\right)` of the Riemann problem defined by .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial y}} = 0\text{,} with :math:`U` and :math:`F` as in `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03puf.html#eqn2>`__, and initial piecewise constant values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`. The spatial domain is :math:`{-\infty } < y < \infty`, where :math:`y = 0` is the point at which the numerical flux is required. This implementation of Roe's scheme for the Euler equations uses the so-called argument-vector method described in Roe (1981). .. _d03pu-py2-py-references: **References** LeVeque, R J, 1990, `Numerical Methods for Conservation Laws`, Birkhäuser Verlag Quirk, J J, 1994, `A contribution to the great Riemann solver debate`, Internat. J. Numer. Methods Fluids (18), 555--574 Roe, P L, 1981, `Approximate Riemann solvers, parameter vectors, and difference schemes`, J. Comput. Phys. (43), 357--372 """ raise NotImplementedError
[docs]def dim1_parab_euler_osher(uleft, uright, gamma, path, comm): r""" ``dim1_parab_euler_osher`` calculates a numerical flux function using Osher's Approximate Riemann Solver for the Euler equations in conservative form. It is designed primarily for use with the upwind discretization schemes :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` or :meth:`dim1_parab_convdiff_remesh`, but may also be applicable to other conservative upwind schemes requiring numerical flux functions. .. _d03pv-py2-py-doc: For full information please refer to the NAG Library document for d03pv https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pvf.html .. _d03pv-py2-py-parameters: **Parameters** **uleft** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uleft}[\textit{i}-1]` must contain the left value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uleft}[0]` must contain the left value of :math:`\rho`, :math:`\mathrm{uleft}[1]` must contain the left value of :math:`m` and :math:`\mathrm{uleft}[2]` must contain the left value of :math:`e`. **uright** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uright}[\textit{i}-1]` must contain the right value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uright}[0]` must contain the right value of :math:`\rho`, :math:`\mathrm{uright}[1]` must contain the right value of :math:`m` and :math:`\mathrm{uright}[2]` must contain the right value of :math:`e`. **gamma** : float The ratio of specific heats, :math:`\gamma`. **path** : str, length 1 The variant of the Osher scheme. :math:`\mathrm{path} = \texttt{'O'}` Original. :math:`\mathrm{path} = \texttt{'P'}` Physical. **comm** : dict, communication object Communication structure. `On initial entry`: need not be set. **Returns** **flux** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{flux}[\textit{i}-1]` contains the numerical flux component :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. .. _d03pv-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{gamma} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{gamma} > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{path} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{path} = \texttt{'O'}` or :math:`\texttt{'P'}`. (`errno` :math:`2`) Right pressure value :math:`\textit{pr} < 0.0`: :math:`\textit{pr} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) Left pressure value :math:`\textit{pl} < 0.0`: :math:`\textit{pl} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) On entry, :math:`\mathrm{uright}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uright}[0]\geq 0.0`. (`errno` :math:`2`) On entry, :math:`\mathrm{uleft}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uleft}[0]\geq 0.0`. .. _d03pv-py2-py-notes: **Notes** ``dim1_parab_euler_osher`` calculates a numerical flux function at a single spatial point using Osher's Approximate Riemann Solver (see Hemker and Spekreijse (1986) and Pennington and Berzins (1994)) for the Euler equations (for a perfect gas) in conservative form. You must supply the `left` and `right` solution values at the point where the numerical flux is required, i.e., the initial left and right states of the Riemann problem defined below. In the functions :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` and :meth:`dim1_parab_convdiff_remesh`, the left and right solution values are derived automatically from the solution values at adjacent spatial points and supplied to the function argument :math:`\textit{numflx}` from which you may call ``dim1_parab_euler_osher``. The Euler equations for a perfect gas in conservative form are: .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial x}} = 0\text{,} with .. math:: U = \left[\begin{array}{c}\rho \\m\\e\end{array}\right]\text{ and }F = \left[\begin{array}{c}m\\\frac{m^2}{\rho }+\left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \\\frac{{me}}{\rho }+\frac{m}{\rho }\left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \end{array}\right]\text{,} where :math:`\rho` is the density, :math:`m` is the momentum, :math:`e` is the specific total energy, and :math:`\gamma` is the (constant) ratio of specific heats. The pressure :math:`p` is given by .. math:: p = \left(\gamma -1\right)\left(e-\frac{{\rho u^2}}{2}\right)\text{,} where :math:`u = m/\rho` is the velocity. The function calculates the Osher approximation to the numerical flux function :math:`F\left(U_L, U_R\right) = F\left({U^*\left(U_L, U_R\right)}\right)`, where :math:`U = U_L` and :math:`U = U_R` are the left and right solution values, and :math:`U^*\left(U_L, U_R\right)` is the intermediate state :math:`\omega \left(0\right)` arising from the similarity solution :math:`U\left(y, t\right) = \omega \left(y/t\right)` of the Riemann problem defined by .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial y}} = 0\text{,} with :math:`U` and :math:`F` as in `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pvf.html#eqn2>`__, and initial piecewise constant values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`. The spatial domain is :math:`{-\infty } < y < \infty`, where :math:`y = 0` is the point at which the numerical flux is required. Osher's solver carries out an integration along a path in the phase space of :math:`U` consisting of subpaths which are piecewise parallel to the eigenvectors of the Jacobian of the PDE system. There are two variants of the Osher solver termed O (original) and P (physical), which differ in the order in which the subpaths are taken. The P-variant is generally more efficient, but in some rare cases may fail (see Hemker and Spekreijse (1986) for details). The argument :math:`\mathrm{path}` specifies which variant is to be used. The algorithm for Osher's solver for the Euler equations is given in detail in the Appendix of Pennington and Berzins (1994). .. _d03pv-py2-py-references: **References** Hemker, P W and Spekreijse, S P, 1986, `Multiple grid and Osher's scheme for the efficient solution of the steady Euler equations`, Applied Numerical Mathematics (2), 475--493 Pennington, S V and Berzins, M, 1994, `New NAG Library software for first-order partial differential equations`, ACM Trans. Math. Softw. (20), 63--99 Quirk, J J, 1994, `A contribution to the great Riemann solver debate`, Internat. J. Numer. Methods Fluids (18), 555--574 """ raise NotImplementedError
[docs]def dim1_parab_euler_hll(uleft, uright, gamma, comm): r""" ``dim1_parab_euler_hll`` calculates a numerical flux function using a modified HLL (Harten--Lax--van Leer) Approximate Riemann Solver for the Euler equations in conservative form. It is designed primarily for use with the upwind discretization schemes :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` or :meth:`dim1_parab_convdiff_remesh`, but may also be applicable to other conservative upwind schemes requiring numerical flux functions. .. _d03pw-py2-py-doc: For full information please refer to the NAG Library document for d03pw https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pwf.html .. _d03pw-py2-py-parameters: **Parameters** **uleft** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uleft}[\textit{i}-1]` must contain the left value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uleft}[0]` must contain the left value of :math:`\rho`, :math:`\mathrm{uleft}[1]` must contain the left value of :math:`m` and :math:`\mathrm{uleft}[2]` must contain the left value of :math:`e`. **uright** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uright}[\textit{i}-1]` must contain the right value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uright}[0]` must contain the right value of :math:`\rho`, :math:`\mathrm{uright}[1]` must contain the right value of :math:`m` and :math:`\mathrm{uright}[2]` must contain the right value of :math:`e`. **gamma** : float The ratio of specific heats, :math:`\gamma`. **comm** : dict, communication object Communication structure. `On initial entry`: need not be set. **Returns** **flux** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{flux}[\textit{i}-1]` contains the numerical flux component :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. .. _d03pw-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{gamma} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{gamma} > 0.0`. (`errno` :math:`2`) Right pressure value :math:`\textit{pr} < 0.0`: :math:`\textit{pr} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) Left pressure value :math:`\textit{pl} < 0.0`: :math:`\textit{pl} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) On entry, :math:`\mathrm{uright}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uright}[0]\geq 0.0`. (`errno` :math:`2`) On entry, :math:`\mathrm{uleft}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uleft}[0]\geq 0.0`. .. _d03pw-py2-py-notes: **Notes** ``dim1_parab_euler_hll`` calculates a numerical flux function at a single spatial point using a modified HLL (Harten--Lax--van Leer) Approximate Riemann Solver (see Toro (1992), Toro (1996) and Toro `et al.` (1994)) for the Euler equations (for a perfect gas) in conservative form. You must supply the `left` and `right` solution values at the point where the numerical flux is required, i.e., the initial left and right states of the Riemann problem defined below. In :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` and :meth:`dim1_parab_convdiff_remesh`, the left and right solution values are derived automatically from the solution values at adjacent spatial points and supplied to the function argument :math:`\textit{numflx}` from which you may call ``dim1_parab_euler_hll``. The Euler equations for a perfect gas in conservative form are: .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial x}} = 0\text{,} with .. math:: U = \left[\begin{array}{c}\rho \\m\\e\end{array}\right]\text{ and }F = \left[\begin{array}{c}m\\\frac{m^2}{\rho }+\left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \\\frac{{me}}{\rho }+\frac{m}{\rho }\left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \end{array}\right]\text{,} where :math:`\rho` is the density, :math:`m` is the momentum, :math:`e` is the specific total energy and :math:`\gamma` is the (constant) ratio of specific heats. The pressure :math:`p` is given by .. math:: p = \left(\gamma -1\right)\left(e-\frac{{\rho u^2}}{2}\right)\text{,} where :math:`u = m/\rho` is the velocity. The function calculates an approximation to the numerical flux function :math:`F\left(U_L, U_R\right) = F\left({U^*\left(U_L, U_R\right)}\right)`, where :math:`U = U_L` and :math:`U = U_R` are the left and right solution values, and :math:`U^*\left(U_L, U_R\right)` is the intermediate state :math:`\omega \left(0\right)` arising from the similarity solution :math:`U\left(y, t\right) = \omega \left(y/t\right)` of the Riemann problem defined by .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial y}} = 0\text{,} with :math:`U` and :math:`F` as in `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pwf.html#eqn2>`__, and initial piecewise constant values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`. The spatial domain is :math:`{-\infty } < y < \infty`, where :math:`y = 0` is the point at which the numerical flux is required. .. _d03pw-py2-py-references: **References** Toro, E F, 1992, `The weighted average flux method applied to the Euler equations`, Phil. Trans. R. Soc. Lond. (A341), 499--530 Toro, E F, 1996, `Riemann Solvers and Upwind Methods for Fluid Dynamics`, Springer--Verlag Toro, E F, Spruce, M and Spears, W, 1994, `Restoration of the contact surface in the HLL Riemann solver`, J. Shock Waves (4), 25--34 """ raise NotImplementedError
[docs]def dim1_parab_euler_exact(uleft, uright, gamma, tol, niter, comm): r""" ``dim1_parab_euler_exact`` calculates a numerical flux function using an Exact Riemann Solver for the Euler equations in conservative form. It is designed primarily for use with the upwind discretization schemes :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` or :meth:`dim1_parab_convdiff_remesh`, but may also be applicable to other conservative upwind schemes requiring numerical flux functions. .. _d03px-py2-py-doc: For full information please refer to the NAG Library document for d03px https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pxf.html .. _d03px-py2-py-parameters: **Parameters** **uleft** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uleft}[\textit{i}-1]` must contain the left value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uleft}[0]` must contain the left value of :math:`\rho`, :math:`\mathrm{uleft}[1]` must contain the left value of :math:`m` and :math:`\mathrm{uleft}[2]` must contain the left value of :math:`e`. **uright** : float, array-like, shape :math:`\left(3\right)` :math:`\mathrm{uright}[\textit{i}-1]` must contain the right value of the component :math:`U_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. That is, :math:`\mathrm{uright}[0]` must contain the right value of :math:`\rho`, :math:`\mathrm{uright}[1]` must contain the right value of :math:`m` and :math:`\mathrm{uright}[2]` must contain the right value of :math:`e`. **gamma** : float The ratio of specific heats, :math:`\gamma`. **tol** : float The tolerance to be used in the Newton--Raphson procedure to calculate the pressure. If :math:`\mathrm{tol}` is set to zero then the default value of :math:`1.0\times 10^{-6}` is used. **niter** : int The maximum number of Newton--Raphson iterations allowed. If :math:`\mathrm{niter}` is set to zero then the default value of :math:`20` is used. **comm** : dict, communication object Communication structure. `On initial entry`: need not be set. **Returns** **flux** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{flux}[\textit{i}-1]` contains the numerical flux component :math:`\hat{F}_{\textit{i}}`, for :math:`\textit{i} = 1,2,\ldots,3`. .. _d03px-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{niter} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{niter} \geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tol} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tol}\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{gamma} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{gamma} > 0.0`. (`errno` :math:`2`) Right pressure value :math:`\textit{pr} < 0.0`: :math:`\textit{pr} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) Left pressure value :math:`\textit{pl} < 0.0`: :math:`\textit{pl} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) On entry, :math:`\mathrm{uright}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uright}[0]\geq 0.0`. (`errno` :math:`2`) On entry, :math:`\mathrm{uleft}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{uleft}[0]\geq 0.0`. (`errno` :math:`3`) A vacuum condition has been detected. (`errno` :math:`4`) Newton--Raphson iteration failed to converge. .. _d03px-py2-py-notes: **Notes** ``dim1_parab_euler_exact`` calculates a numerical flux function at a single spatial point using an Exact Riemann Solver (see Toro (1996) and Toro (1989)) for the Euler equations (for a perfect gas) in conservative form. You must supply the `left` and `right` solution values at the point where the numerical flux is required, i.e., the initial left and right states of the Riemann problem defined below. In :meth:`dim1_parab_convdiff`, :meth:`dim1_parab_convdiff_dae` and :meth:`dim1_parab_convdiff_remesh`, the left and right solution values are derived automatically from the solution values at adjacent spatial points and supplied to the function argument :math:`\textit{numflx}` from which you may call ``dim1_parab_euler_exact``. The Euler equations for a perfect gas in conservative form are: .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial x}} = 0\text{,} with .. math:: U = \left[\begin{array}{c}\rho \\m\\e\end{array}\right]\text{ and }F = \left[\begin{array}{c}m\\\frac{m^2}{\rho }+\left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \\\frac{{me}}{\rho }+\frac{m}{\rho }\left(\gamma -1\right) \left(e-\frac{m^2}{{2\rho }}\right) \end{array}\right]\text{,} where :math:`\rho` is the density, :math:`m` is the momentum, :math:`e` is the specific total energy and :math:`\gamma` is the (constant) ratio of specific heats. The pressure :math:`p` is given by .. math:: p = \left(\gamma -1\right)\left(e-\frac{{\rho u^2}}{2}\right)\text{,} where :math:`u = m/\rho` is the velocity. The function calculates the numerical flux function :math:`F\left(U_L, U_R\right) = F\left({U^*\left(U_L, U_R\right)}\right)`, where :math:`U = U_L` and :math:`U = U_R` are the left and right solution values, and :math:`U^*\left(U_L, U_R\right)` is the intermediate state :math:`\omega \left(0\right)` arising from the similarity solution :math:`U\left(y, t\right) = \omega \left(y/t\right)` of the Riemann problem defined by .. math:: \frac{{\partial U}}{{\partial t}}+\frac{{\partial F}}{{\partial y}} = 0\text{,} with :math:`U` and :math:`F` as in `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pxf.html#eqn2>`__, and initial piecewise constant values :math:`U = U_L` for :math:`y < 0` and :math:`U = U_R` for :math:`y > 0`. The spatial domain is :math:`{-\infty } < y < \infty`, where :math:`y = 0` is the point at which the numerical flux is required. The algorithm is termed an Exact Riemann Solver although it does in fact calculate an approximate solution to a true Riemann problem, as opposed to an Approximate Riemann Solver which involves some form of alternative modelling of the Riemann problem. The approximation part of the Exact Riemann Solver is a Newton--Raphson iterative procedure to calculate the pressure, and you must supply a tolerance :math:`\mathrm{tol}` and a maximum number of iterations :math:`\mathrm{niter}`. Default values for these arguments can be chosen. A solution cannot be found by this function if there is a vacuum state in the Riemann problem (loosely characterised by zero density), or if such a state is generated by the interaction of two non-vacuum data states. In this case a Riemann solver which can handle vacuum states has to be used (see Toro (1996)). .. _d03px-py2-py-references: **References** Toro, E F, 1989, `A weighted average flux method for hyperbolic conservation laws`, Proc. Roy. Soc. Lond. (A423), 401--418 Toro, E F, 1996, `Riemann Solvers and Upwind Methods for Fluid Dynamics`, Springer--Verlag """ raise NotImplementedError
[docs]def dim1_parab_coll_interp(u, xbkpts, npoly, xp, itype, comm): r""" ``dim1_parab_coll_interp`` may be used in conjunction with either :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll`. It computes the solution and its first derivative at user-specified points in the spatial coordinate. .. _d03py-py2-py-doc: For full information please refer to the NAG Library document for d03py https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pyf.html .. _d03py-py2-py-parameters: **Parameters** **u** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npts}\right)` The PDE part of the original solution returned in the argument :math:`\mathrm{u}` by the function :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll`. **xbkpts** : float, array-like, shape :math:`\left(\textit{nbkpts}\right)` :math:`\mathrm{xbkpts}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nbkpts}`, must contain the break-points as used by :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll`. **npoly** : int The degree of the Chebyshev polynomial used for approximation as used by :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll`. **xp** : float, array-like, shape :math:`\left(\textit{intpts}\right)` :math:`\mathrm{xp}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{intpts}`, must contain the spatial interpolation points. **itype** : int Specifies the interpolation to be performed. :math:`\mathrm{itype} = 1` The solution at the interpolation points are computed. :math:`\mathrm{itype} = 2` Both the solution and the first derivative at the interpolation points are computed. **comm** : dict, communication object, modified in place Communication structure. This argument must have been initialized by prior calls to :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll`. **Returns** **up** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{intpts}, \mathrm{itype}\right)` If :math:`\mathrm{itype} = 1`, :math:`\mathrm{up}[\textit{i}-1,\textit{j}-1,0]`, contains the value of the solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_{\mathrm{out}}\right)`, at the interpolation points :math:`x_{\textit{j}} = \mathrm{xp}[\textit{j}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`, for :math:`\textit{j} = 1,2,\ldots,\textit{intpts}`. If :math:`\mathrm{itype} = 2`, :math:`\mathrm{up}[\textit{i}-1,\textit{j}-1,0]` contains :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_{\mathrm{out}}\right)` and :math:`\mathrm{up}[\textit{i}-1,\textit{j}-1,1]` contains :math:`\frac{{\partial U_{\textit{i}}}}{{\partial x}}` at these points. .. _d03py-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{itype} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itype} = 1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xbkpts}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xbkpts}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xbkpts}[0] < \mathrm{xbkpts}[1] < \cdots < \mathrm{xbkpts}[\textit{nbkpts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{nbkpts} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts} = \left(\textit{nbkpts}-1\right)\times \mathrm{npoly}+1`. (`errno` :math:`1`) On entry, :math:`\textit{intpts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{intpts}\geq 1`. (`errno` :math:`1`) On entry, :math:`\mathrm{npoly} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{npoly} > 0`. (`errno` :math:`1`) On entry, :math:`\textit{nbkpts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{nbkpts}\geq 2`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde} > 0`. (`errno` :math:`2`) On entry, :math:`\mathrm{itype} = 2` and at least one interpolation point coincides with a break-point, i.e., interpolation point no :math:`\langle\mathit{\boldsymbol{value}}\rangle` with value :math:`\langle\mathit{\boldsymbol{value}}\rangle` is close to break-point :math:`\langle\mathit{\boldsymbol{value}}\rangle` with value :math:`\langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`2`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xp}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xp}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xbkpts}[0]\leq \mathrm{xp}[0] < \mathrm{xp}[1] < \cdots < \mathrm{xp}[\textit{intpts}-1]\leq \mathrm{xbkpts}[\textit{nbkpts}-1]`. (`errno` :math:`3`) Extrapolation is not allowed. .. _d03py-py2-py-notes: **Notes** ``dim1_parab_coll_interp`` is an interpolation function for evaluating the solution of a system of partial differential equations (PDEs), or the PDE components of a system of PDEs with coupled ordinary differential equations (ODEs), at a set of user-specified points. The solution of a system of equations can be computed using :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll` on a set of mesh points; ``dim1_parab_coll_interp`` can then be employed to compute the solution at a set of points other than those originally used in :meth:`dim1_parab_coll` or :meth:`dim1_parab_dae_coll`. It can also evaluate the first derivative of the solution. Polynomial interpolation is used between each of the break-points :math:`\mathrm{xbkpts}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{nbkpts}`. When the derivative is needed (:math:`\mathrm{itype} = 2`), the array :math:`\mathrm{xp}[\textit{intpts}-1]` must not contain any of the break-points, as the method, and consequently the interpolation scheme, assumes that only the solution is continuous at these points. """ raise NotImplementedError
[docs]def dim1_parab_fd_interp(m, u, x, xp, itype): r""" ``dim1_parab_fd_interp`` interpolates in the spatial coordinate the solution and derivative of a system of partial differential equations (PDEs). The solution must first be computed using one of the finite difference schemes :meth:`dim1_parab_fd`, :meth:`dim1_parab_dae_fd` or :meth:`dim1_parab_remesh_fd`, or one of the Keller box schemes :meth:`dim1_parab_keller`, :meth:`dim1_parab_dae_keller` or :meth:`dim1_parab_remesh_keller`. .. _d03pz-py2-py-doc: For full information please refer to the NAG Library document for d03pz https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03pzf.html .. _d03pz-py2-py-parameters: **Parameters** **m** : int The coordinate system used. If the call to ``dim1_parab_fd_interp`` follows one of the finite difference functions then :math:`\mathrm{m}` must be the same argument :math:`\mathrm{m}` as used in that call. For the Keller box scheme only Cartesian coordinate systems are valid and so :math:`\mathrm{m}` **must** be set to zero. No check will be made by ``dim1_parab_fd_interp`` in this case. :math:`\mathrm{m} = 0` Indicates Cartesian coordinates. :math:`\mathrm{m} = 1` Indicates cylindrical polar coordinates. :math:`\mathrm{m} = 2` Indicates spherical polar coordinates. **u** : float, array-like, shape :math:`\left(\textit{npde}, \textit{npts}\right)` The PDE part of the original solution returned in the argument :math:`\mathrm{u}` by the PDE function. **x** : float, array-like, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, must contain the mesh points as used by the PDE function. **xp** : float, array-like, shape :math:`\left(\textit{intpts}\right)` :math:`\mathrm{xp}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{intpts}`, must contain the spatial interpolation points. **itype** : int Specifies the interpolation to be performed. :math:`\mathrm{itype} = 1` The solutions at the interpolation points are computed. :math:`\mathrm{itype} = 2` Both the solutions and their first derivatives at the interpolation points are computed. **Returns** **up** : float, ndarray, shape :math:`\left(\textit{npde}, \textit{intpts}, \mathrm{itype}\right)` If :math:`\mathrm{itype} = 1`, :math:`\mathrm{up}[\textit{i}-1,\textit{j}-1,0]`, contains the value of the solution :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_{\mathrm{out}}\right)`, at the interpolation points :math:`x_{\textit{j}} = \mathrm{xp}[\textit{j}-1]`, for :math:`\textit{i} = 1,2,\ldots,\textit{npde}`, for :math:`\textit{j} = 1,2,\ldots,\textit{intpts}`. If :math:`\mathrm{itype} = 2`, :math:`\mathrm{up}[\textit{i}-1,\textit{j}-1,0]` contains :math:`U_{\textit{i}}\left(x_{\textit{j}}, t_{\mathrm{out}}\right)` and :math:`\mathrm{up}[\textit{i}-1,\textit{j}-1,1]` contains :math:`\frac{{\partial U_{\textit{i}}}}{{\partial x}}` at these points. .. _d03pz-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{itype} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{itype} = 1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\mathrm{m} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{m} = 0`, :math:`1` or :math:`2`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{x}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{x}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0] < \mathrm{x}[1] < \cdots < \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`1`) On entry, :math:`\textit{intpts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{intpts}\geq 1`. (`errno` :math:`1`) On entry, :math:`\textit{npts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npts} > 2`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde} > 0`. (`errno` :math:`2`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\mathrm{xp}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xp}[\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{x}[0]\leq \mathrm{xp}[0] < \mathrm{xp}[1] < \cdots < \mathrm{xp}[\textit{intpts}-1]\leq \mathrm{x}[\textit{npts}-1]`. (`errno` :math:`3`) On entry, interpolating point :math:`\langle\mathit{\boldsymbol{value}}\rangle` with the value :math:`\langle\mathit{\boldsymbol{value}}\rangle` is outside the :math:`\mathrm{x}` range. .. _d03pz-py2-py-notes: **Notes** ``dim1_parab_fd_interp`` is an interpolation function for evaluating the solution of a system of partial differential equations (PDEs), at a set of user-specified points. The solution of the system of equations (possibly with coupled ordinary differential equations) must be computed using a finite difference scheme or a Keller box scheme on a set of mesh points. ``dim1_parab_fd_interp`` can then be employed to compute the solution at a set of points anywhere in the range of the mesh. It can also evaluate the first spatial derivative of the solution. It uses linear interpolation for approximating the solution. """ raise NotImplementedError
[docs]def dim2_gen_order2_rectangle(ts, tout, dt, xmin, xmax, ymin, ymax, nx, ny, tols, tolt, pdedef, bndary, pdeiv, monitr, opti, optr, comm, itrace, ind, lenrwk=None, leniwk=None, lenlwk=None, data=None, io_manager=None, spiked_sorder='C'): r""" ``dim2_gen_order2_rectangle`` integrates a system of linear or nonlinear, time-dependent partial differential equations (PDEs) in two space dimensions on a rectangular 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_rectangle`` originates from the VLUGR2 package (see Blom and Verwer (1993) and Blom `et al.` (1996)). .. _d03ra-py2-py-doc: For full information please refer to the NAG Library document for d03ra https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html .. _d03ra-py2-py-parameters: **Parameters** **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **dt** : float, array-like, shape :math:`\left(3\right)` The initial, minimum and maximum time step sizes respectively. :math:`\mathrm{dt}[0]` Specifies the initial time step size to be used on the first entry, i.e., when :math:`\mathrm{ind} = 0`. If :math:`\mathrm{dt}[0] = 0.0` then the default value :math:`\mathrm{dt}[0] = 0.01\times \left(\mathrm{tout}-\mathrm{ts}\right)` is used. On subsequent entries (:math:`\mathrm{ind} = 1`), the value of :math:`\mathrm{dt}[0]` is not referenced. :math:`\mathrm{dt}[1]` Specifies the minimum time step size to be attempted by the integrator. If :math:`\mathrm{dt}[1] = 0.0` the default value :math:`\mathrm{dt}[1] = 10.0\times \text{machine precision}` is used. :math:`\mathrm{dt}[2]` Specifies the maximum time step size to be attempted by the integrator. If :math:`\mathrm{dt}[2] = 0.0` the default value :math:`\mathrm{dt}[2] = \mathrm{tout}-\mathrm{ts}` is used. **xmin** : float The extents of the rectangular domain in the :math:`x`-direction, i.e., the :math:`x` coordinates of the left and right boundaries respectively. **xmax** : float The extents of the rectangular domain in the :math:`x`-direction, i.e., the :math:`x` coordinates of the left and right boundaries respectively. **ymin** : float The extents of the rectangular domain in the :math:`y`-direction, i.e., the :math:`y` coordinates of the lower and upper boundaries respectively. **ymax** : float The extents of the rectangular domain in the :math:`y`-direction, i.e., the :math:`y` coordinates of the lower and upper boundaries respectively. **nx** : int The number of grid points in the :math:`x`-direction (including the boundary points). **ny** : int The number of grid points in the :math:`y`-direction (including the boundary points). **tols** : float The space tolerance used in the grid refinement strategy (:math:`\sigma` in equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn4>`__). See `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#fcomments2>`__. **tolt** : float The time tolerance used to determine the time step size (:math:`\tau` in equation `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn7>`__). See `Time Integration <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#fcomments3>`__. **pdedef** : callable res = pdedef(t, x, y, u, ut, ux, uy, uxx, uxy, uyy, data=None) :math:`\mathrm{pdedef}` must evaluate the functions :math:`F_j`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, in equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn1>`__ 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 :math:`\mathrm{bndary}`. :math:`\mathrm{pdedef}` is called for each subgrid in turn. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]` contains the :math:`x` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **y** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{y}[\textit{i}-1]` contains the :math:`y` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **ut** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial t}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **ux** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial x}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **uy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial y}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **uxx** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uxx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2u}}{{\partial x^2}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **uxy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uxy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2u}}{{\partial x\partial y}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **uyy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uyy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2u}}{{\partial y^2}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{res}[\textit{i}-1,\textit{j}-1]` must contain the value of :math:`F_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, at the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, although the residuals at boundary points will be ignored (and overwritten later on) and so they need not be specified here. **bndary** : callable res = bndary(t, x, y, u, ut, ux, uy, lbnd, res, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, in equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn2>`__ which define the boundary conditions at all boundary points of the domain. Residuals at interior points must **not** be altered by this function. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]` contains the :math:`x` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **y** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{y}[\textit{i}-1]` contains the :math:`y` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **ut** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial t}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **ux** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial x}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **uy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial y}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **lbnd** : int, ndarray, shape :math:`\left(\textit{nbpts}\right)` :math:`\mathrm{lbnd}[\textit{i}-1]` contains the grid index for the :math:`\textit{i}`\ th boundary point, for :math:`\textit{i} = 1,2,\ldots,\textit{nbpts}`. Hence the :math:`\textit{i}`\ th boundary point has coordinates :math:`\mathrm{x}[\mathrm{lbnd}[\textit{i}-1]-1]` and :math:`\mathrm{y}[\mathrm{lbnd}[\textit{i}-1]-1]`, and the corresponding solution values are :math:`\mathrm{u}[\mathrm{lbnd}[\textit{i}-1]-1,\mathrm{npde}-1]`, etc. **res** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{res}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`F_{\textit{j}}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npde}`, at the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`, as returned by :math:`\mathrm{pdedef}`. The residuals at the boundary points will be overwritten and so need not have been set by :math:`\mathrm{pdedef}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{res}[\mathrm{lbnd}[\textit{i}-1]-1,\textit{j}-1]` must contain the value of :math:`G_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, at the :math:`\textit{i}`\ th boundary point, for :math:`\textit{i} = 1,2,\ldots,\textit{nbpts}`. Note: elements of :math:`\mathrm{res}` corresponding to interior points must **not** be altered. **pdeiv** : callable u = pdeiv(npde, t, x, y, data=None) :math:`\mathrm{pdeiv}` must specify the initial values of the PDE components :math:`u` at all points in the grid. :math:`\mathrm{pdeiv}` is not referenced if, on entry, :math:`\mathrm{ind} = 1`. **Parameters** **npde** : int The number of PDEs in the system. **t** : float The (initial) value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]` contains the :math:`x` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **y** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{y}[\textit{i}-1]` contains the :math:`y` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\textit{npts}, \mathrm{npde}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` must contain the value of the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\textit{npts}`. **monitr** : callable ierr = monitr(npde, t, dt, dtnew, tlast, ngpts, xpts, ypts, lsol, sol, ierr, data=None) :math:`\mathrm{monitr}` is called by ``dim2_gen_order2_rectangle`` 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 :math:`\mathrm{tlast}`. The input arguments contain information about the grid and solution at all grid levels used. :math:`\mathrm{monitr}` can also be used to force an immediate tidy termination of the solution process and return to the calling program. **Parameters** **npde** : int The number of PDEs in the system. **t** : float The current value of the independent variable :math:`t`, i.e., the time at the end of the integration step just completed. **dt** : float The current time step size :math:`\Delta t`, i.e., the time step size used for the integration step just completed. **dtnew** : float The step size that will be used for the next time step. **tlast** : bool Indicates if intermediate or final time step. :math:`\mathrm{tlast} = \mathbf{False}` for an intermediate step, :math:`\mathrm{tlast} = \mathbf{True}` for the last call to :math:`\mathrm{monitr}` before returning to your program. **ngpts** : int, ndarray, shape :math:`\left(\textit{nlev}\right)` :math:`\mathrm{ngpts}[\textit{l}-1]` contains the number of grid points at level :math:`\textit{l}`, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`. **xpts** : float, ndarray, shape :math:`\left(\mathrm{sum}\left(\mathrm{ngpts}\right)\right)` Contains the :math:`x` coordinates of the grid points in each level in turn, i.e., :math:`\mathrm{x}[\textit{i}-1]`, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngpts}[\textit{l}-1]`. So for level :math:`\textit{l}`, :math:`\mathrm{x}[\textit{i}-1] = \mathrm{xpts}[\textit{k}+\textit{i}-1]`, where :math:`\textit{k} = \mathrm{ngpts}[0]+\mathrm{ngpts}[1] + \cdots +\mathrm{ngpts}[\textit{l}-2]`, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngpts}[\textit{l}-1]`. **ypts** : float, ndarray, shape :math:`\left(\mathrm{sum}\left(\mathrm{ngpts}\right)\right)` Contains the :math:`y` coordinates of the grid points in each level in turn, i.e., :math:`\mathrm{y}[\textit{i}-1]`, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngpts}[\textit{l}-1]`. So for level :math:`\textit{l}`, :math:`\mathrm{y}[\textit{i}-1] = \mathrm{ypts}[\textit{k}+\textit{i}-1]`, where :math:`\textit{k} = \mathrm{ngpts}[0]+\mathrm{ngpts}[1] + \cdots +\mathrm{ngpts}[\textit{l}-2]`, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngpts}[\textit{l}-1]`. **lsol** : int, ndarray, shape :math:`\left(\textit{nlev}\right)` :math:`\mathrm{lsol}[\textit{l}-1]` contains the pointer to the solution in :math:`\mathrm{sol}` at grid level :math:`\textit{l}` and time :math:`\mathrm{t}`. (:math:`\mathrm{lsol}[\textit{l}-1]` actually contains the array index immediately preceding the start of the solution in :math:`\mathrm{sol}`.) **sol** : float, ndarray, shape :math:`\left(:\right)` Contains the solution :math:`\mathrm{u}[\mathrm{ngpts}[\textit{l}-1]-1,\mathrm{npde}-1]` at time :math:`\mathrm{t}` for each grid level :math:`\textit{l}` in turn, positioned according to :math:`\mathrm{lsol}`, i.e., for level :math:`\textit{l}`, :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1] = \mathrm{sol}[\mathrm{lsol}[\textit{l}-1]+\left(\textit{j}-1\right)\times \mathrm{ngpts}[\textit{l}-1]+\textit{i}-1]`, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{ngpts}[\textit{l}-1]`. **ierr** : int Will be set to :math:`0`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **ierr** : int Should be set to :math:`1` to force a tidy termination and an immediate return to the calling program with :math:`\mathrm{errno}` = 4. :math:`\mathrm{ierr}` should remain unchanged otherwise. **opti** : int, array-like, shape :math:`\left(4\right)` May be set to control various options available in the integrator. :math:`\mathrm{opti}[0] = 0` **All** the default options are employed. :math:`\mathrm{opti}[0] > 0` The default value of :math:`\mathrm{opti}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4`, can be obtained by setting :math:`\mathrm{opti}[\textit{i}-1] = 0`. :math:`\mathrm{opti}[0]` Specifies the maximum number of grid levels allowed (including the base grid). :math:`\mathrm{opti}[0]\geq 0`. The default value is :math:`\mathrm{opti}[0] = 3`. :math:`\mathrm{opti}[1]` Specifies the maximum number of Jacobian evaluations allowed during each nonlinear equations solution. :math:`\mathrm{opti}[1]\geq 0`. The default value is :math:`\mathrm{opti}[1] = 2`. :math:`\mathrm{opti}[2]` Specifies the maximum number of Newton iterations in each nonlinear equations solution. :math:`\mathrm{opti}[2]\geq 0`. The default value is :math:`\mathrm{opti}[2] = 10`. :math:`\mathrm{opti}[3]` Specifies the maximum number of iterations in each linear equations solution. :math:`\mathrm{opti}[3]\geq 0`. The default value is :math:`\mathrm{opti}[3] = 100`. **optr** : float, array-like, shape :math:`\left(3, \textit{npde}\right)` May be used to specify the optional vectors :math:`u^{\mathrm{max}}`, :math:`w^{\mathrm{s}}` and :math:`w^{\mathrm{t}}` in the space and time monitors (see `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#fcomments>`__). If an optional vector is not required then all its components should be set to :math:`1.0`. :math:`\mathrm{optr}[0,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, specifies :math:`u_{\textit{j}}^{\mathrm{max}}`, the approximate maximum absolute value of the :math:`\textit{j}`\ th component of :math:`u`, as used in `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn4>`__ and `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn4>`__. :math:`\mathrm{optr}[0,\textit{j}-1] > 0.0`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`. :math:`\mathrm{optr}[1,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, specifies :math:`w_{\textit{j}}^{\mathrm{s}}`, the weighting factors used in the space monitor (see `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn4>`__) to indicate the relative importance of the :math:`\textit{j}`\ th component of :math:`u` on the space monitor. :math:`\mathrm{optr}[1,\textit{j}-1]\geq 0.0`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`. :math:`\mathrm{optr}[2,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, specifies :math:`w_{\textit{j}}^{\mathrm{t}}`, the weighting factors used in the time monitor (see `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn6>`__) to indicate the relative importance of the :math:`\textit{j}`\ th component of :math:`u` on the time monitor. :math:`\mathrm{optr}[2,\textit{j}-1]\geq 0.0`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`. **comm** : dict, communication object, modified in place Communication structure. `On initial entry`: need not be set. **itrace** : int The level of trace information required from ``dim2_gen_order2_rectangle``. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages are printed. :math:`\mathrm{itrace} > 0` Output from the underlying solver is printed. This output contains details of the time integration, the nonlinear iteration and the linear solver. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. Setting :math:`\mathrm{itrace} = 1` allows you to monitor the progress of the integration without possibly excessive information. **ind** : int Must be set to :math:`0` or :math:`1`, alternatively :math:`10` or :math:`11`. :math:`\mathrm{ind} = 0` Starts the integration in time. :math:`\mathrm{pdedef}` is assumed to be serial. :math:`\mathrm{ind} = 1` 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``: :math:`\textit{tout}`, :math:`\textit{dt}`, :math:`\textit{tols}`, :math:`\textit{tolt}`, :math:`\textit{opti}`, :math:`\textit{optr}`, :math:`\textit{itrace}` and :math:`\textit{errno}`. :math:`\mathrm{pdedef}` is assumed to be serial. :math:`\mathrm{ind} = 10` Starts the integration in time. :math:`\mathrm{pdedef}` is assumed to have been parallelized by you, as described in `Parallelism and Performance <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#parallel>`__. In all other respects, this is equivalent to :math:`\mathrm{ind} = 0`. :math:`\mathrm{ind} = 11` 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``: :math:`\textit{tout}`, :math:`\textit{dt}`, :math:`\textit{tols}`, :math:`\textit{tolt}`, :math:`\textit{opti}`, :math:`\textit{optr}`, :math:`\textit{itrace}` and :math:`\textit{errno}`. :math:`\mathrm{pdedef}` is assumed to have been parallelized by you, as described in `Parallelism and Performance <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#parallel>`__. In all other respects, this is equivalent to :math:`\mathrm{ind} = 1`. **lenrwk** : None or int, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`\textit{maxpts}\times \mathrm{npde}\times \left(5\times \textit{maxlev}+18\times \mathrm{npde}+9\right)+2\times \textit{maxpts}`. The required value of :math:`\mathrm{lenrwk}` cannot be determined exactly in advance, but a suggested value is .. math:: \mathrm{lenrwk} = \textit{maxpts}\times \textit{npde}\times \left(5\times \textit{l}+18\times \textit{npde}+9\right)+2\times \textit{maxpts}\text{,} where :math:`\textit{l} = \mathrm{opti}[0]` if :math:`\mathrm{opti}[0]\neq 0` and :math:`\textit{l} = 3` otherwise, and :math:`\textit{maxpts}` 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 :math:`\mathrm{errno}` = 3 and an estimated required size is printed. **leniwk** : None or int, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`\textit{maxpts}\times \left(14+5\times \textit{maxlev}\right)+7+2`. The required value of :math:`\mathrm{leniwk}` cannot be determined exactly in advance, but a suggested value is .. math:: \mathrm{leniwk} = \textit{maxpts}\times \left(14+5\times m\right)+7\times m+2\text{,} where :math:`\textit{maxpts}` is the expected maximum number of grid points at any one level and :math:`m = \mathrm{opti}[0]` if :math:`\mathrm{opti}[0] > 0` and :math:`m = 3` otherwise. If during the execution the supplied value is found to be too small then the function returns with :math:`\mathrm{errno}` = 3 and an estimated required size is printed. **lenlwk** : None or int, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`\textit{maxpts}+1`. The required value of :math:`\mathrm{lenlwk}` cannot be determined exactly in advanced, but a suggested value is .. math:: \mathrm{lenlwk} = \textit{maxpts}+1\text{,} where :math:`\textit{maxpts}` 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 :math:`\mathrm{errno}` = 3 and an estimated required size is printed. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{optr}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. Two-dimensional arrays returned from callback functions in this routine must then use the same storage order. **Returns** **ts** : float The value of :math:`t` which has been reached. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **dt** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{dt}[0]` contains the time step size for the next time step. :math:`\mathrm{dt}[1]` and :math:`\mathrm{dt}[2]` are unchanged or set to their default values if zero on entry. **ind** : int :math:`\mathrm{ind} = 1`, if :math:`\mathrm{ind}` on input was :math:`0` or :math:`1`, or :math:`\mathrm{ind} = 11`, if :math:`\mathrm{ind}` on input was :math:`10` or :math:`11`. .. _d03ra-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{ind}` is not equal to :math:`0` or :math:`1`: :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{lenlwk}` too small for initial grid level: :math:`\mathrm{lenlwk} = \langle\mathit{\boldsymbol{value}}\rangle`, minimum value :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`. Note that subsequent levels will require more. Consult document. (`errno` :math:`1`) On entry, :math:`\mathrm{leniwk}` too small for initial grid level: :math:`\mathrm{leniwk} = \langle\mathit{\boldsymbol{value}}\rangle`, minimum value :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`. Note that subsequent levels will require more. Consult document. (`errno` :math:`1`) On entry, :math:`\mathrm{lenrwk}` too small for initial grid level: :math:`\mathrm{lenrwk} = \langle\mathit{\boldsymbol{value}}\rangle`, minimum value :math:`\text{} = \langle\mathit{\boldsymbol{value}}\rangle`. Note that subsequent levels will require more. Consult document. (`errno` :math:`1`) On entry, :math:`\mathrm{ymax}` too close to :math:`\mathrm{ymin}`: :math:`\mathrm{ymax} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ymin} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{xmax}` too close to :math:`\mathrm{xmin}`: :math:`\mathrm{xmax} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xmin} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{ymin} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ymax} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ymax} > \mathrm{ymin}`. (`errno` :math:`1`) On entry, :math:`\mathrm{xmin} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{xmax} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{xmax} > \mathrm{xmin}`. (`errno` :math:`1`) On entry, :math:`\mathrm{ny} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{ny}\geq 4`. (`errno` :math:`1`) On entry, :math:`\mathrm{nx} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{nx}\geq 4`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{dt}[2] = \langle\mathit{\boldsymbol{value}}\rangle`. Note that :math:`\mathrm{dt}[2]` was reset to default if zero on entry. Constraint: if :math:`\mathrm{ind} = 0`, :math:`\mathrm{dt}[0]\leq \mathrm{dt}[2]`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{dt}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. Note that :math:`\mathrm{dt}[1]` was reset to default if zero on entry. Constraint: if :math:`\mathrm{ind} = 0`, :math:`\mathrm{dt}[0]\geq \mathrm{dt}[1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = 0` and :math:`\mathrm{dt}[0]` too large: :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\text{maximum value} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = 0` and :math:`\mathrm{dt}[0]` too small: :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\text{minimum value} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: if :math:`\mathrm{ind} = 0`, :math:`\mathrm{dt}[0]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[1] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{dt}[2] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dt}[1]\leq \mathrm{dt}[2]`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[2] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dt}[2]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dt}[1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{optr}[\textit{i}-1,\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{optr}[\textit{i}-1,\textit{j}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{optr}[0,\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{optr}[0,\textit{j}-1] > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{opti}[0] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{opti}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: if :math:`\mathrm{opti}[0] > 0`, :math:`\mathrm{opti}[\textit{i}-1]\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{opti}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{opti}[0]\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tolt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tolt} > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tols} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tols} > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` too small: :math:`\mathrm{tout}-\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`2`) Attempted time-step smaller than specified minimum. Check problem formulation in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}` and :math:`\mathrm{pdeiv}`. Try increasing :math:`\mathrm{itrace}` for more information. (`errno` :math:`3`) One or more of the workspace arrays are too small. Try increasing :math:`\mathrm{itrace}` for more information. **Warns** **NagAlgorithmicWarning** (`errno` :math:`4`) :math:`\mathrm{IERR}` set to :math:`1` in :math:`\mathrm{monitr}`. Integration completed as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`5`) Integration completed, but maximum number of levels too small for required accuracy. .. _d03ra-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_gen_order2_rectangle`` integrates the system of PDEs: .. math:: F_j\left(t, x, y, u, u_t, u_x, u_y, u_{{xx}}, u_{{xy}}, u_{{yy}}\right) = 0\text{, }\quad j = 1,2,\ldots,\textit{npde}\text{,} for :math:`x` and :math:`y` in the rectangular domain :math:`x_{\mathrm{min}}\leq x\leq x_{\mathrm{max}}`, :math:`y_{\mathrm{min}}\leq y\leq y_{\mathrm{max}}`, and time interval :math:`t_0\leq t\leq t_{\mathrm{out}}`, where the vector :math:`u` is the set of solution values .. math:: u\left(x, y, t\right) = {\left[{u_1\left(x, y, t\right)}, \ldots, {u_{\textit{npde}}\left(x, y, t\right)}\right]}^{\mathrm{T}}\text{,} and :math:`u_t` denotes partial differentiation with respect to :math:`t`, and similarly for :math:`u_x` etc. The functions :math:`F_j` must be supplied by you in :math:`\mathrm{pdedef}`. Similarly the initial values of the functions :math:`u\left(x, y, t\right)` must be specified at :math:`t = t_0` in :math:`\mathrm{pdeiv}`. Note that whilst complete generality is offered by the master equations `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#eqn1>`__, ``dim2_gen_order2_rectangle`` is not appropriate for all PDEs. In particular, hyperbolic systems should not be solved using this function. Also, at least one component of :math:`u_t` must appear in the system of PDEs. The boundary conditions must be supplied by you in :math:`\mathrm{bndary}` in the form .. math:: G_j\left(t, x, y, u, u_t, u_x, u_y\right) = 0\text{,} for all :math:`y` when :math:`x_{\mathrm{min}}` or :math:`x_{\mathrm{max}}` and for all :math:`x` when :math:`y = y_{\mathrm{min}}` or :math:`y = y_{\mathrm{max}}` and :math:`j = 1,2,\ldots,\textit{npde}` The domain is covered by a uniform coarse base grid of size :math:`n_x\times n_y` 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 :math:`\mathrm{tols}`. 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 :math:`\mathrm{opti}` and :math:`\mathrm{optr}`. Further details of the refinement strategy can be found in `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#fcomments>`__. 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 :math:`\mathrm{tolt}`, and some further optional user-specified weighting factors held in :math:`\mathrm{optr}` (see `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#fcomments>`__ 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 :math:`\mathrm{dt}`. The step size is adjusted so that the remaining integration interval is an integer number times :math:`\Delta t`. In this way a solution is obtained at :math:`t = t_{\mathrm{out}}`. A modified Newton method is used to solve the nonlinear equations arising from the time integration. You may specify (in :math:`\mathrm{opti}`) 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 :math:`\Delta t = \Delta t/4`. 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 :math:`\mathrm{opti}`. The solution at all grid levels is 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 included. The user-supplied monitor :math:`\mathrm{monitr}` should be used to obtain the solution at particular levels and times. :math:`\mathrm{monitr}` is called at the end of every time step, with the last step being identified via the input argument :math:`\mathrm{tlast}`. Within :math:`\mathrm{pdeiv}`, :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}` and :math:`\mathrm{monitr}` the data structure is as follows. Each point on a particular grid is given an index (ranging from :math:`1` to the total number of points on the grid) and all coordinate or solution information is stored in arrays according to this index, e.g., :math:`\mathrm{x}[i-1]` and :math:`\mathrm{y}[i-1]` contain the :math:`x`- and :math:`y` coordinate of point :math:`i`, and :math:`\mathrm{u}[i-1,j-1]` contains the :math:`j`\ th solution component :math:`u_j` at point :math:`i`. Further details of the underlying algorithm can be found in `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03raf.html#fcomments>`__ and in Blom and Verwer (1993) and Blom `et al.` (1996) and the references therein. .. _d03ra-py2-py-references: **References** Adjerid, S and Flaherty, J E, 1988, `A local refinement finite element method for two-dimensional parabolic systems`, SIAM J. Sci. Statist. Comput. (9), 792--811 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 Brown, P N, Hindmarsh, A C and Petzold, L R, 1994, `Using Krylov methods in the solution of large scale differential-algebraic systems`, SIAM J. Sci. Statist. Comput. (15), 1467--1488 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 See Also -------- :meth:`naginterfaces.library.examples.pde.dim2_gen_order2_rectangle_ex.main` """ raise NotImplementedError
[docs]def 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'): r""" ``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)). .. _d03rb-py2-py-doc: For full information please refer to the NAG Library document for d03rb https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html .. _d03rb-py2-py-parameters: **Parameters** **ts** : float The initial value of the independent variable :math:`t`. **tout** : float The final value of :math:`t` to which the integration is to be carried out. **dt** : float, array-like, shape :math:`\left(3\right)` The initial, minimum and maximum time step sizes respectively. :math:`\mathrm{dt}[0]` Specifies the initial time step size to be used on the first entry, i.e., when :math:`\mathrm{ind} = 0`. If :math:`\mathrm{dt}[0] = 0.0` then the default value :math:`\mathrm{dt}[0] = 0.01\times \left(\mathrm{tout}-\mathrm{ts}\right)` is used. On subsequent entries (:math:`\mathrm{ind} = 1`), the value of :math:`\mathrm{dt}[0]` is not referenced. :math:`\mathrm{dt}[1]` Specifies the minimum time step size to be attempted by the integrator. If :math:`\mathrm{dt}[1] = 0.0` the default value :math:`\mathrm{dt}[1] = 10.0\times \text{machine precision}` is used. :math:`\mathrm{dt}[2]` Specifies the maximum time step size to be attempted by the integrator. If :math:`\mathrm{dt}[2] = 0.0` the default value :math:`\mathrm{dt}[2] = \mathrm{tout}-\mathrm{ts}` is used. **tols** : float The space tolerance used in the grid refinement strategy (:math:`\sigma` in equation `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn4>`__). See `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#fcomments2>`__. **tolt** : float The time tolerance used to determine the time step size (:math:`\tau` in equation `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn7>`__). See `Time Integration <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#fcomments3>`__. **inidom** : callable (xmin, xmax, ymin, ymax, nx, ny, npts, nrows, nbnds, nbpts, lrow, irow, icol, llbnd, ilbnd, lbnd, ierr) = inidom(maxpts, ierr, data=None) :math:`\mathrm{inidom}` must specify the base grid in terms of the data structure described in :ref:`Notes <d03rb-py2-py-notes>`. :math:`\mathrm{inidom}` is not referenced if, on entry, :math:`\mathrm{ind} = 1`. 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 :math:`3` grid points including the corners. If Neumann boundary conditions are to be applied the minimum is :math:`4`. **Parameters** **maxpts** : int The maximum number of base grid points allowed by the available workspace. **ierr** : int Will be initialized by ``dim2_gen_order2_rectilinear`` to some value prior to internal calls to :math:`\mathrm{inidom}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **xmin** : float The extents of the virtual grid in the :math:`x`-direction, i.e., the :math:`x` coordinates of the left and right boundaries respectively. **xmax** : float The extents of the virtual grid in the :math:`x`-direction, i.e., the :math:`x` coordinates of the left and right boundaries respectively. **ymin** : float The extents of the virtual grid in the :math:`y`-direction, i.e., the :math:`y` coordinates of the left and right boundaries respectively. **ymax** : float The extents of the virtual grid in the :math:`y`-direction, i.e., the :math:`y` coordinates of the left and right boundaries respectively. **nx** : int The number of virtual grid points in the :math:`x`- and :math:`y`-direction respectively (including the boundary points). **ny** : int The number of virtual grid points in the :math:`x`- and :math:`y`-direction respectively (including the boundary points). **npts** : int The total number of points in the base grid. If the required number of points is greater than :math:`\mathrm{maxpts}` then :math:`\mathrm{inidom}` must be exited immediately with :math:`\mathrm{ierr}` set to :math:`-1` to avoid overwriting memory. **nrows** : int The total number of rows of the virtual grid that contain base grid points. This is the maximum base row index. **nbnds** : int The total number of physical boundaries and corners in the base grid. **nbpts** : int The total number of boundary points in the base grid. **lrow** : int, array-like, shape :math:`\left(\mathrm{maxpts}\right)` :math:`\mathrm{lrow}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nrows}`, must contain the base grid index of the first grid point in base grid row :math:`\textit{i}`. **irow** : int, array-like, shape :math:`\left(\mathrm{maxpts}\right)` :math:`\mathrm{irow}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nrows}`, must contain the virtual row number :math:`v_y` that corresponds to base grid row :math:`\textit{i}`. **icol** : int, array-like, shape :math:`\left(\mathrm{maxpts}\right)` :math:`\mathrm{icol}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`, must contain the virtual column number :math:`v_x` that contains base grid point :math:`\textit{i}`. **llbnd** : int, array-like, shape :math:`\left(\mathrm{maxpts}\right)` :math:`\mathrm{llbnd}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbnds}`, must contain the element of :math:`\mathrm{lbnd}` corresponding to the start of the :math:`\textit{i}`\ th boundary or corner. Note: the order of the boundaries and corners in :math:`\mathrm{llbnd}` 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. **ilbnd** : int, array-like, shape :math:`\left(\mathrm{maxpts}\right)` :math:`\mathrm{ilbnd}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbnds}`, must contain the type of the :math:`\textit{i}`\ th boundary (or corner), as given in :ref:`Notes <d03rb-py2-py-notes>`. **lbnd** : int, array-like, shape :math:`\left(\mathrm{maxpts}\right)` :math:`\mathrm{lbnd}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbpts}`, must contain the grid index of the :math:`\textit{i}`\ th boundary point. The order of the boundaries is as specified in :math:`\mathrm{llbnd}`, but within this restriction the order of the points in :math:`\mathrm{lbnd}` is arbitrary. **ierr** : int If the required number of grid points is larger than :math:`\mathrm{maxpts}`, :math:`\mathrm{ierr}` must be set to :math:`-1` to force a termination of the integration and an immediate return to the calling program with :math:`\mathrm{errno}` = 3. Otherwise, :math:`\mathrm{ierr}` should remain unchanged. **pdedef** : callable res = pdedef(t, x, y, u, ut, ux, uy, uxx, uxy, uyy, data=None) :math:`\mathrm{pdedef}` must evaluate the functions :math:`F_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, in equation `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn1>`__ 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 :math:`\mathrm{bndary}`. :math:`\mathrm{pdedef}` is called for each subgrid in turn. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]` contains the :math:`x` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **y** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{y}[\textit{i}-1]` contains the :math:`y` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **ut** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial t}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **ux** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial x}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **uy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial y}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **uxx** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uxx}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2u}}{{\partial x^2}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **uxy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uxy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2u}}{{\partial x\partial y}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **uyy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uyy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial^2u}}{{\partial y^2}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{res}[\textit{i}-1,\textit{j}-1]` must contain the value of :math:`F_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, at the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`, although the residuals at boundary points will be ignored (and overwritten later on) and so they need not be specified here. **bndary** : callable res = bndary(t, x, y, u, ut, ux, uy, llbnd, ilbnd, lbnd, res, data=None) :math:`\mathrm{bndary}` must evaluate the functions :math:`G_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, in equation `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn2>`__ which define the boundary conditions at all boundary points of the domain. Residuals at interior points must **not** be altered by this function. **Parameters** **t** : float The current value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]` contains the :math:`x` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **y** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{y}[\textit{i}-1]` contains the :math:`y` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **u** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` contains the value of the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **ut** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ut}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial t}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **ux** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{ux}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial x}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **uy** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{uy}[\textit{i}-1,\textit{j}-1]` contains the value of :math:`\frac{{\partial u}}{{\partial y}}` for the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **llbnd** : int, ndarray, shape :math:`\left(\textit{nbnds}\right)` :math:`\mathrm{llbnd}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbnds}`, contains the element of :math:`\mathrm{lbnd}` corresponding to the start of the :math:`\textit{i}`\ th boundary (or corner). **ilbnd** : int, ndarray, shape :math:`\left(\textit{nbnds}\right)` :math:`\mathrm{ilbnd}[\textit{i}-1]`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbnds}`, contains the type of the :math:`\textit{i}`\ th boundary, as given in :ref:`Notes <d03rb-py2-py-notes>`. **lbnd** : int, ndarray, shape :math:`\left(\textit{nbpts}\right)` :math:`\mathrm{lbnd}[\textit{i}-1]`, contains the grid index of the :math:`\textit{i}`\ th boundary point, where the order of the boundaries is as specified in :math:`\mathrm{llbnd}`. Hence the :math:`\textit{i}`\ th boundary point has coordinates :math:`\mathrm{x}[\mathrm{lbnd}[\textit{i}-1]-1]` and :math:`\mathrm{y}[\mathrm{lbnd}[\textit{i}-1]-1]`, and the corresponding solution values are :math:`\mathrm{u}[\mathrm{lbnd}[\textit{i}-1]-1,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbpts}`. **res** : float, ndarray, shape :math:`\left(\textit{npts}, \textit{npde}\right)` Contains function values returned by :math:`\mathrm{pdedef}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **res** : float, array-like, shape :math:`\left(\textit{npts}, \textit{npde}\right)` :math:`\mathrm{res}[\mathrm{lbnd}[\textit{i}-1]-1,\textit{j}-1]` must contain the value of :math:`G_{\textit{j}}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, at the :math:`\textit{i}`\ th boundary point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{nbpts}`. Note: elements of :math:`\mathrm{res}` corresponding to interior points, i.e., points not included in :math:`\mathrm{lbnd}`, must **not** be altered. **pdeiv** : callable u = pdeiv(npde, t, x, y, data=None) :math:`\mathrm{pdeiv}` must specify the initial values of the PDE components :math:`u` at all points in the base grid. :math:`\mathrm{pdeiv}` is not referenced if, on entry, :math:`\mathrm{ind} = 1`. **Parameters** **npde** : int The number of PDEs in the system. **t** : float The (initial) value of the independent variable :math:`t`. **x** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{x}[\textit{i}-1]` contains the :math:`x` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **y** : float, ndarray, shape :math:`\left(\textit{npts}\right)` :math:`\mathrm{y}[\textit{i}-1]` contains the :math:`y` coordinate of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **u** : float, array-like, shape :math:`\left(\textit{npts}, \mathrm{npde}\right)` :math:`\mathrm{u}[\textit{i}-1,\textit{j}-1]` must contain the value of the :math:`\textit{j}`\ th PDE component at the :math:`\textit{i}`\ th grid point, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **monitr** : callable ierr = monitr(npde, t, dt, dtnew, tlast, xmin, ymin, dxb, dyb, lgrid, istruc, lsol, sol, ierr, data=None) :math:`\mathrm{monitr}` 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 :math:`\mathrm{tlast}`. The input arguments contain information about the grid and solution at all grid levels used. :meth:`dim2_gen_order2_rectilinear_extractgrid` should be called from :math:`\mathrm{monitr}` in order to extract the number of points and their :math:`\left(x, y\right)` coordinates on a particular grid. :math:`\mathrm{monitr}` can also be used to force an immediate tidy termination of the solution process and return to the calling program. **Parameters** **npde** : int The number of PDEs in the system. **t** : float The current value of the independent variable :math:`t`, i.e., the time at the end of the integration step just completed. **dt** : float The current time step size :math:`\Delta t`, i.e., the time step size used for the integration step just completed. **dtnew** : float The time step size that will be used for the next time step. **tlast** : bool Indicates if intermediate or final time step. :math:`\mathrm{tlast} = \mathbf{False}` for an intermediate step, :math:`\mathrm{tlast} = \mathbf{True}` for the last call to :math:`\mathrm{monitr}` before returning to your program. **xmin** : float The :math:`\left(x, y\right)` coordinates of the lower-left corner of the virtual grid. **ymin** : float The :math:`\left(x, y\right)` coordinates of the lower-left corner of the virtual grid. **dxb** : float The sizes of the base grid spacing in the :math:`x`- and :math:`y`-direction respectively. **dyb** : float The sizes of the base grid spacing in the :math:`x`- and :math:`y`-direction respectively. **lgrid** : int, ndarray, shape :math:`\left(\textit{nlev}+1\right)` Contains pointers to the start of the grid structures in :math:`\mathrm{istruc}`, and must be passed unchanged to :meth:`dim2_gen_order2_rectilinear_extractgrid` in order to extract the grid information. **istruc** : int, ndarray, shape :math:`\left(\textit{nistruc}\right)` Contains the grid structures for each grid level and must be passed unchanged to :meth:`dim2_gen_order2_rectilinear_extractgrid` in order to extract the grid information. **lsol** : int, ndarray, shape :math:`\left(\textit{nlev}\right)` :math:`\mathrm{lsol}[l-1]` contains the pointer to the solution in :math:`\mathrm{sol}` at grid level :math:`l` and time :math:`\mathrm{t}`. (:math:`\mathrm{lsol}[l-1]` actually contains the array index immediately preceding the start of the solution in :math:`\mathrm{sol}`.) **sol** : float, ndarray, shape :math:`\left(\textit{nsol}\right)` Contains the solution :math:`u` at time :math:`\mathrm{t}` for each grid level :math:`l` in turn, positioned according to :math:`\mathrm{lsol}`. More precisely .. math:: \mathrm{u}[\textit{i}-1,\textit{j}-1] = \mathrm{sol}[ \mathrm{lsol}[\textit{l}-1] + \left(\textit{j}-1\right) \times n_{\textit{l}}+\textit{i} -1] represents the :math:`\textit{j}`\ th component of the solution at the :math:`\textit{i}`\ th grid point in the :math:`\textit{l}`\ th level, for :math:`\textit{l} = 1,2,\ldots,\textit{nlev}`, for :math:`\textit{j} = 1,2,\ldots,\mathrm{npde}`, for :math:`\textit{i} = 1,2,\ldots,n_{\textit{l}}`, where :math:`n_{\textit{l}}` is the number of grid points at level :math:`\textit{l}` (obtainable by a call to :meth:`dim2_gen_order2_rectilinear_extractgrid`). **ierr** : int Will be initialized by ``dim2_gen_order2_rectilinear`` to some value prior to internal calls to :math:`\mathrm{ierr}`. **data** : arbitrary, optional, modifiable in place User-communication data for callback functions. **Returns** **ierr** : int Should be set to :math:`1` to force a termination of the integration and an immediate return to the calling program with :math:`\mathrm{errno}` = 4. :math:`\mathrm{ierr}` should remain unchanged otherwise. **opti** : int, array-like, shape :math:`\left(4\right)` May be set to control various options available in the integrator. :math:`\mathrm{opti}[0] = 0` **All** the default options are employed. :math:`\mathrm{opti}[0] > 0` The default value of :math:`\mathrm{opti}[\textit{i}-1]`, for :math:`\textit{i} = 2,3,\ldots,4`, can be obtained by setting :math:`\mathrm{opti}[\textit{i}-1] = 0`. :math:`\mathrm{opti}[0]` Specifies the maximum number of grid levels allowed (including the base grid). :math:`\mathrm{opti}[0]\geq 0`. The default value is :math:`\mathrm{opti}[0] = 3`. :math:`\mathrm{opti}[1]` Specifies the maximum number of Jacobian evaluations allowed during each nonlinear equations solution. :math:`\mathrm{opti}[1]\geq 0`. The default value is :math:`\mathrm{opti}[1] = 2`. :math:`\mathrm{opti}[2]` Specifies the maximum number of Newton iterations in each nonlinear equations solution. :math:`\mathrm{opti}[2]\geq 0`. The default value is :math:`\mathrm{opti}[2] = 10`. :math:`\mathrm{opti}[3]` Specifies the maximum number of iterations in each linear equations solution. :math:`\mathrm{opti}[3]\geq 0`. The default value is :math:`\mathrm{opti}[3] = 100`. **optr** : float, array-like, shape :math:`\left(3, \textit{npde}\right)` May be used to specify the optional vectors :math:`u^{\mathrm{max}}`, :math:`w^s` and :math:`w^t` in the space and time monitors (see `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#fcomments>`__). If an optional vector is not required then all its components should be set to :math:`1.0`. :math:`\mathrm{optr}[0,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, specifies :math:`u_{\textit{j}}^{\mathrm{max}}`, the approximate maximum absolute value of the :math:`\textit{j}`\ th component of :math:`u`, as used in `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn4>`__ and `(7) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn4>`__. :math:`\mathrm{optr}[0,\textit{j}-1] > 0.0`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`. :math:`\mathrm{optr}[1,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, specifies :math:`w_{\textit{j}}^s`, the weighting factors used in the space monitor (see `(4) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn4>`__) to indicate the relative importance of the :math:`\textit{j}`\ th component of :math:`u` on the space monitor. :math:`\mathrm{optr}[1,\textit{j}-1]\geq 0.0`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`. :math:`\mathrm{optr}[2,\textit{j}-1]`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`, specifies :math:`w_{\textit{j}}^t`, the weighting factors used in the time monitor (see `(6) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn6>`__) to indicate the relative importance of the :math:`\textit{j}`\ th component of :math:`u` on the time monitor. :math:`\mathrm{optr}[2,\textit{j}-1]\geq 0.0`, for :math:`\textit{j} = 1,2,\ldots,\textit{npde}`. **comm** : dict, communication object, modified in place Communication structure. `On initial entry`: need not be set. **itrace** : int The level of trace information required from ``dim2_gen_order2_rectilinear``. :math:`\mathrm{itrace}` may take the value :math:`-1`, :math:`0`, :math:`1`, :math:`2` or :math:`3`. :math:`\mathrm{itrace} = -1` No output is generated. :math:`\mathrm{itrace} = 0` Only warning messages are printed. :math:`\mathrm{itrace} > 0` Output from the underlying solver is printed. This output contains details of the time integration, the nonlinear iteration and the linear solver. If :math:`\mathrm{itrace} < -1`, :math:`-1` is assumed and similarly if :math:`\mathrm{itrace} > 3`, :math:`3` is assumed. The advisory messages are given in greater detail as :math:`\mathrm{itrace}` increases. Setting :math:`\mathrm{itrace} = 1` allows you to monitor the progress of the integration without possibly excessive information. **ind** : int Must be set to :math:`0` or :math:`1`, alternatively :math:`10` or :math:`11`. :math:`\mathrm{ind} = 0` Starts the integration in time. :math:`\mathrm{pdedef}` is assumed to be serial. :math:`\mathrm{ind} = 1` 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``: :math:`\textit{tout}`, :math:`\textit{dt}`, :math:`\textit{tols}`, :math:`\textit{tolt}`, :math:`\textit{opti}`, :math:`\textit{optr}`, :math:`\textit{itrace}` and :math:`\textit{errno}`. :math:`\mathrm{pdedef}` is assumed to be serial. :math:`\mathrm{ind} = 10` Starts the integration in time. :math:`\mathrm{pdedef}` is assumed to have been parallelized by you, as described in `Parallelism and Performance <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#parallel>`__. In all other respects, this is equivalent to :math:`\mathrm{ind} = 0`. :math:`\mathrm{ind} = 11` Continues the integration after an earlier exit from the function. In this case, only the following parameters may be reset between calls to :meth:`dim2_gen_order2_rectangle`: :math:`\textit{tout}`, :math:`\textit{dt}`, :math:`\textit{tols}`, :math:`\textit{tolt}`, :math:`\textit{opti}`, :math:`\textit{optr}`, :math:`\textit{itrace}` and :math:`\textit{errno}`. :math:`\mathrm{pdedef}` is assumed to have been parallelized by you, as described in `Parallelism and Performance <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#parallel>`__. In all other respects, this is equivalent to :math:`\mathrm{ind} = 1`. **lenrwk** : None or int, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`\textit{maxpts}\times \mathrm{npde}\times \left(5\times \textit{maxlev}+18\times \mathrm{npde}+9\right)+2\times \textit{maxpts}`. The required value of :math:`\mathrm{lenrwk}` cannot be determined exactly in advance, but a suggested value is .. math:: \mathrm{lenrwk} = \textit{maxpts}\times \textit{npde}\times \left(5\times l+18\times \textit{npde}+9\right)+2\times \textit{maxpts}\text{,} where :math:`l = \mathrm{opti}[0]` if :math:`\mathrm{opti}[0]\neq 0` and :math:`l = 3` otherwise, and :math:`\textit{maxpts}` 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 :math:`\mathrm{errno}` = 3 and an estimated required size is printed on the current error message unit (see :class:`~naginterfaces.base.utils.FileObjManager`). Note: the size of :math:`\mathrm{lenrwk}` cannot be checked upon initial entry to ``dim2_gen_order2_rectilinear`` since the number of grid points on the base grid is not known. **leniwk** : None or int, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`\textit{maxpts}\times \left(14+5\times \textit{maxlev}\right)+7+2`. The required value of :math:`\mathrm{leniwk}` cannot be determined exactly in advance, but a suggested value is .. math:: \mathrm{leniwk} = \textit{maxpts}\times \left(14+5\times m\right)+7\times m+2\text{,} where :math:`\textit{maxpts}` is the expected maximum number of grid points at any one level and :math:`m = \mathrm{opti}[0]` if :math:`\mathrm{opti}[0] > 0` and :math:`m = 3` otherwise. If during the execution the supplied value is found to be too small then the function returns with :math:`\mathrm{errno}` = 3 and an estimated required size is printed on the current error message unit (see :class:`~naginterfaces.base.utils.FileObjManager`). Note: the size of :math:`\mathrm{leniwk}` cannot be checked upon initial entry to ``dim2_gen_order2_rectilinear`` since the number of grid points on the base grid is not known. **lenlwk** : None or int, optional Note: if this argument is **None** then a default value will be used, determined as follows: :math:`\textit{maxpts}+1`. The required value of :math:`\mathrm{lenlwk}` cannot be determined exactly in advance, but a suggested value is .. math:: \mathrm{lenlwk} = \textit{maxpts}+1\text{,} where :math:`\textit{maxpts}` 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 :math:`\mathrm{errno}` = 3 and an estimated required size is printed. Note: the size of :math:`\mathrm{lenlwk}` cannot be checked upon initial entry to ``dim2_gen_order2_rectilinear`` since the number of grid points on the base grid is not known. **data** : arbitrary, optional User-communication data for callback functions. **io_manager** : FileObjManager, optional Manager for I/O in this routine. **spiked_sorder** : str, optional If :math:`\mathrm{optr}` is spiked (i.e., has unit extent in all but one dimension, or has size :math:`1`), :math:`\mathrm{spiked\_sorder}` selects the storage order to associate with it in the NAG Engine: spiked_sorder = :math:`\texttt{'C'}` row-major storage will be used; spiked_sorder = :math:`\texttt{'F'}` column-major storage will be used. Two-dimensional arrays returned from callback functions in this routine must then use the same storage order. **Returns** **ts** : float The value of :math:`t` which has been reached. Normally :math:`\mathrm{ts} = \mathrm{tout}`. **dt** : float, ndarray, shape :math:`\left(3\right)` :math:`\mathrm{dt}[0]` contains the time step size for the next time step. :math:`\mathrm{dt}[1]` and :math:`\mathrm{dt}[2]` are unchanged or set to their default values if zero on entry. **ind** : int :math:`\mathrm{ind} = 1`, if :math:`\mathrm{ind}` on input was :math:`0` or :math:`1`, or :math:`\mathrm{ind} = 11`, if :math:`\mathrm{ind}` on input was :math:`10` or :math:`11`. .. _d03rb-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{ind}` is not equal to :math:`0` or :math:`1`: :math:`\mathrm{ind} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\textit{npde} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\textit{npde}\geq 1`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{dt}[2] = \langle\mathit{\boldsymbol{value}}\rangle`. Note that :math:`\mathrm{dt}[2]` was reset to default if zero on entry. Constraint: if :math:`\mathrm{ind} = 0`, :math:`\mathrm{dt}[0]\leq \mathrm{dt}[2]`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{dt}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. Note that :math:`\mathrm{dt}[1]` was reset to default if zero on entry. Constraint: if :math:`\mathrm{ind} = 0`, :math:`\mathrm{dt}[0]\geq \mathrm{dt}[1]`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = 0` and :math:`\mathrm{dt}[0]` too large: :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\text{maximum value} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{ind} = 0` and :math:`\mathrm{dt}[0]` too small: :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\text{minimum value} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: if :math:`\mathrm{ind} = 0`, :math:`\mathrm{dt}[0]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[1] = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{dt}[2] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dt}[1]\leq \mathrm{dt}[2]`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[2] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dt}[2]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{dt}[1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{dt}[1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{optr}[\textit{i}-1,\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{optr}[\textit{i}-1,\textit{j}-1]\geq 0.0`. (`errno` :math:`1`) On entry, :math:`\textit{j} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{optr}[0,\textit{j}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{optr}[0,\textit{j}-1] > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{opti}[0] = \langle\mathit{\boldsymbol{value}}\rangle`, :math:`\textit{i} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{opti}[\textit{i}-1] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: if :math:`\mathrm{opti}[0] > 0`, :math:`\mathrm{opti}[\textit{i}-1]\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{opti}[0] = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{opti}[0]\geq 0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tolt} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tolt} > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tols} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tols} > 0.0`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout}-\mathrm{ts}` too small: :math:`\mathrm{tout}-\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`1`) On entry, :math:`\mathrm{tout} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{tout} > \mathrm{ts}`. (`errno` :math:`2`) Attempted time-step smaller than specified minimum. Check problem formulation in :math:`\mathrm{pdedef}`, :math:`\mathrm{bndary}` and :math:`\mathrm{pdeiv}`. Try increasing :math:`\mathrm{itrace}` for more information. (`errno` :math:`3`) One or more of the workspace arrays are too small. Try increasing :math:`\mathrm{itrace}` for more information. (`errno` :math:`6`) Invalid output argument from :math:`\mathrm{inidom}`. **Warns** **NagAlgorithmicWarning** (`errno` :math:`4`) :math:`\mathrm{IERR}` set to :math:`1` in :math:`\mathrm{monitr}`. Integration completed as far as :math:`\mathrm{ts}`: :math:`\mathrm{ts} = \langle\mathit{\boldsymbol{value}}\rangle`. (`errno` :math:`5`) Integration completed, but maximum number of levels too small for required accuracy. .. _d03rb-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_gen_order2_rectilinear`` integrates the system of PDEs: .. math:: F_j\left(t, x, y, u, u_t, u_x, u_y, u_{{xx}}, u_{{xy}}, u_{{yy}}\right) = 0\text{, }\quad j = 1,2,\ldots,\textit{npde}\text{, }\quad \left(x, y\right) \in \Omega \text{, }\quad t_0\leq t\leq t_{\mathrm{out}}\text{,} where :math:`\Omega` is an arbitrary rectilinear domain, i.e., a domain bounded by perpendicular straight lines. If the domain is rectangular then it is recommended that :meth:`dim2_gen_order2_rectangle` is used. The vector :math:`u` is the set of solution values .. math:: u\left(x, y, t\right) = {\left[{u_1\left(x, y, t\right)}, \ldots, {u_{\textit{npde}}\left(x, y, t\right)}\right]}^{\mathrm{T}}\text{,} and :math:`u_t` denotes partial differentiation with respect to :math:`t`, and similarly for :math:`u_x`, etc. The functions :math:`F_j` must be supplied by you in :math:`\mathrm{pdedef}`. Similarly the initial values of the functions :math:`u\left(x, y, t\right)` for :math:`\left(x, y\right) \in \Omega` must be specified at :math:`t = t_0` in :math:`\mathrm{pdeiv}`. Note that whilst complete generality is offered by the master equations `(1) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#eqn1>`__, ``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 :math:`u_t` must appear in the system of PDEs. The boundary conditions must be supplied by you in :math:`\mathrm{bndary}` in the form .. math:: G_j\left(t, x, y, u, u_t, u_x, u_y\right) = 0\text{, }\quad j = 1,2,\ldots,\textit{npde}\text{, }\quad \left(x, y\right) \in \partial \Omega \text{, }\quad t_0\leq t\leq t_{\mathrm{out}}\text{.} 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 :math:`\mathrm{tols}`. 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 :math:`\mathrm{opti}` and :math:`\mathrm{optr}`. Further details of the refinement strategy can be found in `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#fcomments>`__. 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 :math:`\mathrm{tolt}`, and some further optional user-specified weighting factors held in :math:`\mathrm{optr}` (see `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#fcomments>`__ 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 :math:`\mathrm{dt}`. The step size is adjusted so that the remaining integration interval is an integer number times :math:`\Delta t`. In this way a solution is obtained at :math:`t = t_{\mathrm{out}}`. A modified Newton method is used to solve the nonlinear equations arising from the time integration. You may specify (in :math:`\mathrm{opti}`) 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 :math:`\Delta t = \Delta t/4`. 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 :math:`\mathrm{opti}`. 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 :math:`\left(x, y\right)` space is given by the :math:`\left(x, y\right)` coordinates of its boundaries. The number of points :math:`n_x` and :math:`n_y` in the :math:`x` and :math:`y` directions must also be given, corresponding to the number of columns and rows respectively. This is sufficient to determine precisely the :math:`\left(x, y\right)` coordinates of all virtual grid points. Each virtual grid point is then referred to by integer coordinates :math:`\left(v_x, v_y\right)`, where :math:`\left(0, 0\right)` corresponds to the lower-left corner and :math:`\left({n_x-1}, {n_y-1}\right)` corresponds to the upper-right corner. :math:`v_x` and :math:`v_y` 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 :math:`1`, 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 :math:`1` contains grid point :math:`1`. 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 :math:`6` say is in base row :math:`2`, virtual column 4, and virtual row :math:`1`, i.e., virtual grid integer coordinates :math:`\left(4, 1\right)`; and the base grid point with index :math:`19` say is in base row :math:`5`, virtual column 2, and virtual row :math:`5`, i.e., virtual grid integer coordinates :math:`\left(2, 5\right)`. The base grid must then be defined in :math:`\mathrm{inidom}` 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: :math:`\mathrm{lrow}` contains the base grid indices of the starting points of the base grid rows; :math:`\mathrm{irow}` contains the virtual row numbers :math:`v_y` of the base grid rows; :math:`\mathrm{icol}` contains the virtual column numbers :math:`v_x` of the base grid points; :math:`\mathrm{lbnd}` contains the grid indices of the boundary edges (without corners) and corner points; :math:`\mathrm{llbnd}` contains the starting elements of the boundaries and corners in :math:`\mathrm{lbnd}`. Finally, :math:`\mathrm{ilbnd}` 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 (:math:`90°`): 12 -- lower-left corner 23 -- upper-left corner 34 -- upper-right corner 41 -- lower-right corner Internal corners (:math:`270°`): 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 :math:`\mathrm{lbnd}`. [figure omitted] For this example we would set :math:`\mathrm{nrows}` to :math:`11` set :math:`\mathrm{npts}` to :math:`105` set :math:`\mathrm{nbnds}` to :math:`28` set :math:`\mathrm{nbpts}` to :math:`72` set :math:`\mathrm{lrow}` to the vector :math:`\left(1,4,15,26,37,46,57,68,79,88,97\right)` set :math:`\mathrm{irow}` to the vector :math:`\left(0,1,2,3,4,5,6,7,8,9,10\right)` set :math:`\mathrm{icol}` to the vector :math:`\left(0,1,2,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,9,10,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8,0,1,2,3,4,5,6,7,8\right)` set :math:`\mathrm{lbnd}` to the vector :math:`\left(2,4,15,26,37,46,57,68,79,88,98,99,100,101,102,103,104,96,86,85,84,83,82,70,59,48,39,28,17,6,8,9,10,11,12,13,18,29,40,49,60,72,73,74,75,76,77,67,56,45,36,25,33,32,42,52,53,43,1,97,105,87,81,3,7,71,78,14,31,51,54,34\right)` set :math:`\mathrm{llbnd}` to the vector :math:`\left(1,2,11,18,19,24,31,37,42,48,53,55,56,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72\right)` set :math:`\mathrm{ilbnd}` to the vector :math:`\left(1,2,3,4,1,4,1,2,3,4,3,4,1,2,12,23,34,41,14,41,12,23,34,41,43,14,21,32\right)` Subgrids are stored internally using the same data structure, and solution information is communicated to you in :math:`\mathrm{pdeiv}`, :math:`\mathrm{pdedef}` and :math:`\mathrm{bndary}` in arrays according to the grid index on the particular level, e.g., :math:`\mathrm{x}[i-1]` and :math:`\mathrm{y}[i-1]` contain the :math:`\left(x, y\right)` coordinates of grid point :math:`i`, and :math:`\mathrm{u}[i-1,j-1]` contains the :math:`j`\ th solution component :math:`u_j` at grid point :math:`i`. 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 (:math:`\mathrm{monitr}`) should be used to obtain the solution at particular levels and times. :math:`\mathrm{monitr}` is called at the end of every time step, with the last step being identified via the input argument :math:`\mathrm{tlast}`. The function :meth:`dim2_gen_order2_rectilinear_extractgrid` should be called from :math:`\mathrm{monitr}` to obtain grid information at a particular level. Further details of the underlying algorithm can be found in `Further Comments <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rbf.html#fcomments>`__ and in Blom and Verwer (1993) and Blom `et al.` (1996) and the references therein. .. _d03rb-py2-py-references: **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 """ raise NotImplementedError
[docs]def dim2_gen_order2_rectilinear_extractgrid(level, xmin, ymin, dxb, dyb, lgrid, istruc, lenxy): r""" ``dim2_gen_order2_rectilinear_extractgrid`` is designed to be used in conjunction with :meth:`dim2_gen_order2_rectilinear`. It can be called from the :math:`\textit{monitr}` to obtain the number of grid points and their :math:`\left(x, y\right)` coordinates on a solution grid. .. _d03rz-py2-py-doc: For full information please refer to the NAG Library document for d03rz https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03rzf.html .. _d03rz-py2-py-parameters: **Parameters** **level** : int The grid level at which the coordinates are required. **xmin** : float :math:`\mathrm{xmin}` as supplied to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid`` **ymin** : float :math:`\mathrm{ymin}` as supplied to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid`` **dxb** : float :math:`\mathrm{dxb}` as supplied to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid`` **dyb** : float :math:`\mathrm{dyb}` as supplied to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid`` **lgrid** : int, array-like, shape :math:`\left(\textit{nlev}\right)` :math:`\mathrm{lgrid}` as supplied to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid``. **istruc** : int, array-like, shape :math:`\left(\mathrm{lgrid}[{\textit{nlev}-1}]+2\times \textit{nrows}+\textit{npts}+1\right)` :math:`\mathrm{istruc}` as supplied to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid``. **lenxy** : int The dimension of the arrays :math:`\mathrm{x}` and :math:`\mathrm{y}`. **Returns** **npts** : int The number of grid points in the grid level :math:`\mathrm{level}`. **x** : float, ndarray, shape :math:`\left(\mathrm{lenxy}\right)` :math:`\mathrm{x}[\textit{i}-1]` and :math:`\mathrm{y}[\textit{i}-1]` contain the :math:`\left(x, y\right)` coordinates respectively of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. **y** : float, ndarray, shape :math:`\left(\mathrm{lenxy}\right)` :math:`\mathrm{x}[\textit{i}-1]` and :math:`\mathrm{y}[\textit{i}-1]` contain the :math:`\left(x, y\right)` coordinates respectively of the :math:`\textit{i}`\ th grid point, for :math:`\textit{i} = 1,2,\ldots,\mathrm{npts}`. .. _d03rz-py2-py-errors: **Raises** **NagValueError** (`errno` :math:`1`) On entry, :math:`\mathrm{level} = \langle\mathit{\boldsymbol{value}}\rangle` and :math:`\textit{nlev} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{level}\leq \textit{nlev}`. (`errno` :math:`1`) On entry, :math:`\mathrm{level} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{level} \geq 1`. (`errno` :math:`2`) On entry, :math:`\mathrm{lenxy} = \langle\mathit{\boldsymbol{value}}\rangle`. Constraint: :math:`\mathrm{lenxy} \geq \langle\mathit{\boldsymbol{value}}\rangle`. .. _d03rz-py2-py-notes: **Notes** `No equivalent traditional C interface for this routine exists in the NAG Library.` ``dim2_gen_order2_rectilinear_extractgrid`` extracts the number of grid points and their :math:`\left(x, y\right)` coordinates on a specific solution grid produced by :meth:`dim2_gen_order2_rectilinear`. It must be called only from within the :math:`\textit{monitr}`. The arguments :math:`\textit{nlev}`, :math:`\textit{xmin}`, :math:`\textit{ymin}`, :math:`\textit{dxb}`, :math:`\textit{dyb}`, :math:`\textit{lgrid}` and :math:`\textit{istruc}` to :math:`\textit{monitr}` must be passed unchanged to ``dim2_gen_order2_rectilinear_extractgrid``. """ raise NotImplementedError
[docs]def dim2_ellip_fd_iter(a, b, c, d, e, aparam, it, r): r""" ``dim2_ellip_fd_iter`` performs at each call one iteration of the Strongly Implicit Procedure. It is used to calculate on successive calls a sequence of approximate corrections to the current estimate of the solution when solving a system of simultaneous algebraic equations for which the iterative update matrix is of five-point molecule form on a two-dimensional topologically-rectangular mesh. ('Topological' means that a polar grid :math:`\left(r, \theta \right)`, for example, can be used as it is equivalent to a rectangular box.) .. _d03ua-py2-py-doc: For full information please refer to the NAG Library document for d03ua https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03uaf.html .. _d03ua-py2-py-parameters: **Parameters** **a** : float, array-like, shape :math:`\left(\textit{n1}, \textit{n2}\right)` :math:`\mathrm{a}[\textit{i}-1,\textit{j}-1]` must contain the coefficient of the 'southerly' term involving :math:`s_{{i,j-1}}` in the :math:`\left(i, j\right)`\ th equation of the system `(2) <https://www.nag.com/numeric/nl/nagdoc_27.3/flhtml/d03/d03uaf.html#eqn2>`__, for :math:`\textit{j} = 1,2,\ldots,\textit{n2}`, for :math:`\textit{i} = 1,2,\ldots,\textit{n1}`. The elements of :math:`\mathrm{a}`, for :math:`j = 1`, must be zero after incorporating the boundary conditions, since they involve nodal values from outside the rectangle. **b** : float, array-like, shape :math:`\left