If you use the Python interface dolfin
to FEniCS, you can simply use the functions of Scipy's io
module to read and write mat files.
An assembled form M
you can export to a sparse matrix like
import scipy.sparse as sps
dolfin.parameters.linear_algebra_backend = "uBLAS"
rows, cols, values = M.data()
Ma = sps.csr_matrix((values, cols, rows))
A function u
you becomes an array like
ua = u.vector().array()
If you want to go the other way round, assign the vector array to a dolfin
function u
using the vector().setlocal
of u
. However, I don't know how to convert back a sparse matrix to an assembled form.