My problem is with exporting sparse matrices created in FEniCS, (e.g., to SciPy or Matlab).
I know that there were Q&As on the issue, but it seems that the solutions I have found:
http://fenicsproject.org/qa/8400/csr-representation-of-ublas-matrix
http://fenicsproject.org/qa/2257/how-to-read-data-from-class-matrix
http://fenicsproject.org/qa/3221/how-to-import-matrix-in-matlab-to-fenics
no longer apply in FEniCS 1.6.0.
I also know that the uBLAS
linear algebra backend is no longer supported and it is advised to use the Eigen
backend instead:
http://fenicsproject.org/qa/8166/query-on-parameters-linear_algebra_backend-ublas
However, it seems that the Eigen
backend is not working properly. In the below code, I'm trying to assemble a matrix using the Eigen
backend and then access its data:
from dolfin import *
parameters['linear_algebra_backend'] = 'Eigen'
N = 4
mesh = UnitSquareMesh(N,N)
V = FunctionSpace(mesh,"Lagrange",1)
u, v = TrialFunction(V), TestFunction(V)
MassMat = assemble(u*v*dx)
print MassMat.data()
getting an error:
Traceback (most recent call last):
File "error.py", line 15, in <module>
print MassMat.data()
AttributeError: 'Matrix' object has no attribute 'data'
It seems that MassMat
is not recognized as an EigenMatrix
class instance.
However, the class EigenMatrix
itself works correctly. Running the below gives no errors:
from dolfin import *
M = EigenMatrix(3,3)
print M.data()
But what I want is to play with the MassMat
created with the assemble
function. Is there anything I'm doing wrong or is it a bug? If a bug, is there any other method to export a sparse matrix created in FEniCS 1.6.0? If not, the only option seems to be downgrading to older FEniCS releases, with uBLAS
support, which is not a solution I dream of.
=====
P.S. There is also an issue concerning the sparray()
method which I don't understand. The below code:
from dolfin import *
M = EigenMatrix(3,3)
print M.sparray()
gives an error:
Traceback (most recent call last):
File "error.py", line 8, in <module>
print M.sparray()
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/la.py", line 2245, in sparray
C = csr_matrix((data[2], data[1], data[0]))
File "/usr/lib/python2.7/dist-packages/scipy/sparse/compressed.py", line 77, in __init__
raise ValueError('unable to infer matrix dimensions')
ValueError: unable to infer matrix dimensions
is there something more I need to do with the M.sparray()
data to handle it properly?