Convert the solution in Function class and assembled operator to numpy array or scipy.csr_matrix vice and versa #3103
-
Dear community, I use firedrake to solve a problem: I can build the operator A and RHS b, and solve A*x=b to get x, which is Function. Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
MatrixI have been hacking around and found the following solution to get a scipy petsc_mat = firedrake_matrix.M.handle
ai, aj, av = petsc_mat.getValuesCSR()
scipy_matrix = scipy.sparse.csr_matrix((av, aj, ai)) Note that this should probably not be attempted in parallel. For the inverse operation see this post. VectorFiredrake |
Beta Was this translation helpful? Give feedback.
Matrix
I have been hacking around and found the following solution to get a scipy
csr_matrix
from a FiredrakeMatrix
:Note that this should probably not be attempted in parallel.
For the inverse operation see this post.
Vector
Firedrake
Function
s are natively stored as numpy arrays so this is a simple operation. You just wantfunction.dat.data