I implement Crank-Nicolson 2D finite-difference method.
I get a matrix A which is banded with 1 band above and below the main diagonal, but also contains 2 additional bands , further apart from the main diagonal, so it is NOT penta-diagonal.
A picture showing the structure is below. My matrix is the RHS one. The LHS is easy, it's the penta-diagonal one.
I couldn't find up until now a way to solve Ax = b with A being the RHS matrix from the photo in python. I could barely find a name for it, in these lecture notes https://ocw.mit.edu/ans7870/2/2.086/F12/MIT2_086F12_notes_unit5.pdf it is called an 'outrigger' matrix (page 403).
At the moment I am using spsolve
from from scipy.sparse.linalg
, into which I feed two arguments, namely sparse.csc_matrix(A)
and sparse.csc_array(b)
, where A
and b
have been defined initially as A = sparse.dok_matrix((size, size), dtype=np.complex64)
and b = sparse.dok_array((size, 1), dtype=np.complex64)
, then populated with values by iterating element by element through them.
It is extremely slow and I was wondering maybe someone more experienced knows a way to exploit the structure appearing in A
.
Thank you!