Creating Sparse matrix

Dear sir,
I am not able to create a spares matrix by the following code.

import numpy as N
import scipy.sparse
source_coord = N.array([0,0,0], dtype=N.float64)
field_pts = N.array([1,0,0])*(N.arange(90)/100+1/10)[:, N.newaxis]
domain_size = N.array([2*3]*3)
import dolfin

As far as I am aware, the uBlasSparseMatrix was deprectated with the release 1.6.0 [2015-07-28]. You are most likely looking at some very old documentation to find this function

1 Like

Thank you, Sir,

Is there any function that is similar to uBlasSparseMatrix in dolfin version 2019.2.0?

One more doubt, Sir,
Is it possible to add a matrix with complex coefficient i,e., A+1j*B, where A and B are matrices.?

is it possible to obtain a variational form with a complex coefficient?
i.e., inner(u,v)dx+1jinner(curl(u), curl(v))*dx, where j is complex number.

we need to look at the above challenges since they are very useful in the study of Maxwell’s equation.

As I have never used uBlasSparseMatrix, as it predates my time working on dolfin, I do not know what you would like to use this matrix for, and thus I cant suggest a substitute.

For complex number support, you need to use dolfin-x, or decompose your problems as sketched out here; Complex eigenvalue problem - #2 by nate

Here they are not mentioned that how to multiply the complex number to global matrix. I can explain even more clear that is

A=2j*np.array([[1,2,3], [0,2,4], [2,8,9]])

output is

[[0. +2.j 0. +4.j 0. +6.j]
[0. +0.j 0. +4.j 0. +8.j]
[0. +4.j 0.+16.j 0.+18.j]]


we can not multiply the complex number to matrix A, where A is the global matrix obtained by variational form

a=inner(curl(u), curl(v))*dx

for the above code, I am not able to get output.

Please look into the issue, it may help most of the people who are working in the field of electromagnetic.

Old dolfin does not have native support for primitive type complex numbers.

A in your example is an assembled PETScMatrix of reals, not a numpy matrix. Unless you configured PETSc with complex support, you cannot simply multiply it by python’s complex unit.

Perhaps investigate dolfinx which does have support for complex PETSc, e.g. the Helmholtz demo.

Or you can convert your PETScMatrix to a numpy or scipy sparse matrix at your leisure.

1 Like

thank you, sir,

i am trying to do what you mentioned above but I am not able to. So can you give a demo.