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

CSR representation of uBLAS matrix

0 votes

Hello

I want to extract non-zero elements from uBLAS matrices, as done here with python, dolfin-version 1.4.
However, when i do

r, c, v = A.data()

the returned list v contain also zero elements.
Below is an example with explicit test. Why is e.g. A[0,5] returned, yet it is zero?
What am i missing?
Thanks!

from dolfin import *
from numpy import set_printoptions

set_printoptions(linewidth=200)
parameters["linear_algebra_backend"] = 'uBLAS'

mesh = UnitSquareMesh(3, 3)
V = FunctionSpace(mesh, 'Lagrange', 1)
u = TrialFunction(V)
v = TestFunction(V)
a = inner(nabla_grad(u), nabla_grad(v))*dx

A = assemble(a)
r, c, v = A.data()
print A.array()
print "C", c
print "R", r
print "V", v

if A.array()[0, 5] == 0:
    print "is zero"
else:
    print "is non-zero"
asked Oct 25, 2015 by adoll FEniCS Novice (530 points)
edited Oct 25, 2015 by adoll

1 Answer

+1 vote
 
Best answer

The CRS structure is based on the sparsity pattern of the dof map rather than the weak form.
Therefore you may add together different matrices as long as they are made
from the same mesh and elements. The number of extra zeros is still few, O(N), where N is the
number of dofs.

answered Oct 25, 2015 by Kent-Andre Mardal FEniCS Expert (14,380 points)
selected Oct 25, 2015 by adoll

Btw, thanks for free support on sunday :)

...