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#
|
Return half bandwidths of a 2D array. |
|
Approximate the Jacobian pattern. |
|
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.bandwidthfunction to determine the lower and upper bandwidths of a given array. Use in conjunction withj_patternto 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
rhsfnabout the given point to determine the Jacobian pattern. It requires evaluating the given functionNtimes based on the size ofy0so 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(andyp0). 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
IDAorCVODEproblem. Signatures vary, see the class docstrings for more info. The correct routine is automatically selected depending on whether or notyp0is given. IDA requires thatyp0be 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 functionF_ieither is or is not dependedent on variabley_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 `Athat 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.