sksundae.jacband#

Routines for analyzing Jacobian patterns and structures for problems involving systems of differential-algebraic equations. For example, finding the sparsity pattern and/or bandwidth.

Functions#

bandwidth(A)

Return half bandwidths of a 2D array.

j_pattern(rhsfn, t0, y0[, yp0, userdata])

Approximate the Jacobian pattern.

reduce_bandwidth(A[, symmetric])

Find a row/col reordering to reduce bandwidth.

Module Contents#

sksundae.jacband.bandwidth(A)[source]#

Return half bandwidths of a 2D array.

Uses the scipy.linalg.bandwidth function to determine the lower and upper bandwidths of a given array. Use in conjunction with j_pattern to find the bandwidths of a Jacobian pattern.

Parameters:

A (2D np.array) – Input array of size (N, M).

Returns:

bands (tuple[int]) – A 2-tuple of integers indicating the lower and upper half bandwidths of the given matrix. A zero denotes that there are no non-zero elements on that side. The full bandwidth is lband + uband + 1.

sksundae.jacband.j_pattern(rhsfn, t0, y0, yp0=None, userdata=None)[source]#

Approximate the Jacobian pattern.

This function uses a numerical Jacobian approximation for rhsfn about the given point to determine the Jacobian pattern. It requires evaluating the given function N times based on the size of y0 so it can be slow for large systems.

Be aware that this routine may return zeros in locations where ones should be depending on the evaluation point y0 (and yp0). It is left to the user to determine a representative evaluation point that ensures all relevant relationships are correctly determined.

Parameters:
  • rhsfn (Callable) – Right-hand-side function for either an IDA or CVODE problem. Signatures vary, see the class docstrings for more info. The correct routine is automatically selected depending on whether or not yp0 is given. IDA requires that yp0 be given and CVODE expects it to be None.

  • t0 (float) – Input time to use in ‘rhsfn’.

  • y0 (ndarray) – State variables to use in ‘rhsfn’.

  • yp0 (ndarray or None, optional) – State variable time derivatives to use in ‘rhsfn’, by default None.

  • userdata (Any, optional) – Additional data to pass to ‘rhsfn’, by default None.

Returns:

pattern (2D np.array) – Jacobian pattern represented by a 2D numpy array with shape (N, N). Ones or zeros in the position A[i, j] mean that function F_i either is or is not dependedent on variable y_j, respectively.

sksundae.jacband.reduce_bandwidth(A, symmetric=False)[source]#

Find a row/col reordering to reduce bandwidth.

Uses the Reverse Cuthill-McKee algorithm from scipy.sparse.csgraph`o determine an index rearragement for rows and columns of `A that reduce the bandwidth.

Parameters:
  • A (ndarray | spmatrix) – A 2D (n, n) input matrix whose sparsity pattern will be reduced.

  • symmetric (bool, optional) – True if input matrix is guaranteed symmetric, otherwise False (default).

Returns:

  • perm (ndarray) – Array of permuted row and column indices such that B = A[perm][:, perm] is a maxtrix with reduced bandwidth compared to A.

  • inv_perm (ndarray) – The inverse of ‘perm’ such that B[inv_perm][:, inv_perm] returns the original matrix A.