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

Lots of zero when using `getrow` on `dolfin Matrix`

0 votes

When I try to use getrow() function on dolfin matrix.

A = assemble(a)
A.getrow(0)

where a is PDE system I have. The result is:

[array([0, 1, 2, 3, 4, 5, 6, 7, 8], dtype=uint64), 
array([  1.62760417e-02,   0.00000000e+00, -8.13802083e-05, 8.13802083e-03,   0.00000000e+00,  -4.06901042e-05, 8.13802083e-03,   0.00000000e+00,  -4.06901042e-05])]

As you can see, there are entries of 0.000000e00 also being printed out. Is this expected? I thought getrow should only return non-zero indices.

asked Dec 9, 2015 by quangha FEniCS Novice (490 points)

1 Answer

+1 vote
 
Best answer

To get a matrix as a sparse matrix, use:

parameters['linear_algebra_backend'] = 'Eigen'

A = assemble(u*v*dx)  # for example

sparr = as_backend_type(A).sparray()
answered Dec 9, 2015 by chris_richardson FEniCS Expert (31,740 points)
selected Jan 26, 2016 by quangha

Thanks, Chris. How about the zero elements that was showed as well? I thought these should not be stored instead?

...