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

Assemble system matrix

0 votes

Hello

My goal is to assemble a system matrix A which is used in

solve(A, x, b)

from other matrices A1,...,An which are constructed as GenericMatrix by

Ak = assemble(inner(nabla_grad(u), nabla_grad(v)) * dx)
bc.apply(Ak)

The matrices A1,...,An posess the same sparsity structure.
In my understanding there is no way to add up generic matrices (am i wrong here?).

Since it is convinient for me to handle the matrix adding rowwise, i use uBLAS to get the CSR representation with

r, c, val = Ak.data()

and reassemble the matrix when i'm finished by

A_sps = scipy.sparse.crs_matrix((summedVals, r, c), dtype=np.float_)
A = assemble(inner(nabla_grad(u), nabla_grad(v)) * dx)
bc.apply(A)
A.zero()
A.set(A_sps, whole, whole)

similar as done here by setting the whole matrix and not just some blocks.

The reassembling step is very slow as it is already noted in loggs answer, however i don't understand his hints about the Assembler object.
Could someone please provide sample code for this?
Or is there a simpler way without scipys crs_matrix? As far as i understand i cannot set a GenericMatrix with CSR data?
Thanks

asked Oct 27, 2015 by adoll FEniCS Novice (530 points)
edited Oct 27, 2015 by adoll

1 Answer

+2 votes
 
Best answer

In assemble you may submit an already initialized matrix M by
A = assemble (...., tensor=M)

To add together matrices you may use the axpy function.

The functionality provided by GenericMatrix is only used during assemble.
For more functions, like axpy, look at the backend-specific matrices.

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