visualdynamics.core.sparse_solve¶
sparse_solve
¶
A sparse symmetric matrix factored once and solved many times, by the fastest solver the machine has.
The modal solve of a large model factors (K - sigma M) once and solves with it a few hundred times: every Lanczos step and every polish step is a solve. On macOS the factorization is Apple's, in the Accelerate framework every Mac carries (Sparse Solvers: a supernodal Cholesky, or LDLT when the matrix is not positive definite), reached through ctypes from the layouts in its public header. Everywhere else, and wherever Accelerate refuses a matrix, it is SuperLU's LU through scipy, told the matrix is symmetric so it orders and pivots for that.
Classes:
| Name | Description |
|---|---|
SuperLUFactor |
SuperLU's factorization of a symmetric matrix, through scipy. |
AccelerateFactor |
Apple's supernodal factorization of a symmetric matrix: Cholesky, |
Functions:
| Name | Description |
|---|---|
probe_backward_error |
|A x - b| / |b| for one solve with a fixed right-hand side, the |
count_below |
How many eigenvalues of K phi = lambda M phi lie below |
factor_symmetric |
The matrix factored, by Accelerate where it is and takes the |
Classes¶
SuperLUFactor
¶
SuperLU's factorization of a symmetric matrix, through scipy.
Methods:
| Name | Description |
|---|---|
solve |
X with A X = |
Source code in src/visualdynamics/core/sparse_solve.py
AccelerateFactor
¶
Apple's supernodal factorization of a symmetric matrix: Cholesky, or LDLT when the matrix is not positive definite.
Raises ValueError when Accelerate refuses the matrix, naming its
status, so the caller can fall back.
Methods:
| Name | Description |
|---|---|
solve |
X with A X = |
Source code in src/visualdynamics/core/sparse_solve.py
Methods:¶
solve
¶
X with A X = rhs, for one right-hand side or a block of
them, in the shape rhs came in.
Source code in src/visualdynamics/core/sparse_solve.py
Functions:¶
probe_backward_error
¶
|A x - b| / |b| for one solve with a fixed right-hand side, the cosines of the row numbers; infinite when the answer is not.
Source code in src/visualdynamics/core/sparse_solve.py
count_below
¶
How many eigenvalues of K phi = lambda M phi lie below shift,
read off the signs of one factorization of K - shift M.
By Sylvester's law of inertia, a symmetric matrix factored as L D Lᵀ has as many negative entries in D as it has negative eigenvalues, and the negative eigenvalues of K - shift M are the modes below the shift (M positive definite). SuperLU in symmetric mode with no pivoting off the diagonal is that factorization, its U's diagonal being D, which is why the threshold is zero here and not the factor the solves use. A pivot within round-off of zero, from a shift on top of an eigenvalue, has a sign that is round-off, so a caller allows the count one either way.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stiffness
|
scipy.sparse matrix
|
K and M, symmetric, M positive definite. |
required |
mass
|
scipy.sparse matrix
|
K and M, symmetric, M positive definite. |
required |
shift
|
float
|
The eigenvalue to count below, (rad/s)². |
required |
Returns:
| Type | Description |
|---|---|
int
|
The count, rigid-body modes included when the shift is above zero. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the factorization fails or had to pivot off the diagonal, so its signs are not the inertia. |
References
A standard method, used here to size the search up to a frequency:
- J. J. Sylvester, A demonstration of the theorem that every homogeneous quadratic polynomial is reducible by real orthogonal substitutions to the form of a sum of positive and negative squares, Philosophical Magazine, 1852.
Source code in src/visualdynamics/core/sparse_solve.py
factor_symmetric
¶
factor_symmetric(matrix: Any) -> AccelerateFactor | SuperLUFactor
The matrix factored, by Accelerate where it is and takes the
matrix, else by SuperLU; both answer solve(rhs) and shape.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
sparse matrix
|
Square and symmetric. |
required |
Returns:
| Type | Description |
|---|---|
AccelerateFactor or SuperLUFactor
|
|