This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Convert dolfin::Matrix into Eigen::Matrix

0 votes

Hi !

I have given a dolfin::Matrix M, which I have built through dolfin::assemble. It could be, for example, the mass matrix of a FE discretization.

Now, I would like to convert this matrix M into an Eigen::MatrixXd.

Do you know an efficient way to do this?

I would be very grateful for any help!
Moerni

asked Nov 10, 2015 by Moerni FEniCS Novice (120 points)

1 Answer

0 votes

It should be fairly easy. Try:

parameters['linear_algebra_backend'] = 'Eigen'
M = Matrix()
M0 = as_backend_type(M)
answered Nov 10, 2015 by chris_richardson FEniCS Expert (31,740 points)

Thanks for your quick reply!
I am using C++ ... so do you know how to use "as_backend_type" there?
Thanks in advance!

You should be able to assemble directly into an EigenMatrix as it inherits from GenericMatrix.

...