What is the easy way to view a matrix in Legacy DOLFIN

Hello. this is a question regarding the legacy dolfin.

I want to adopt some of my code to DOLFINX, in order to monitor the change I want to see the elements of the matrix, so I just want to ask what is the easist way to print a matrix in Legacy dolfin, say I have a bilinear form:

a = (inner(grad(u), grad(v)) + c*v + u*d)*dx

how can I print the resulting matrix, it seems like there so many types of matrix, but I don’t care what type to use and just want to see the component of the matrix.

Thanks!

Use A=dolfinx.fem.assemble_matrix(dolfinx.fem.form(a))
and then use either
https://docs.fenicsproject.org/dolfinx/v0.7.3/python/generated/dolfinx.la.html#dolfinx.la.MatrixCSR.to_dense
or
https://docs.fenicsproject.org/dolfinx/v0.7.3/python/generated/dolfinx.la.html#dolfinx.la.MatrixCSR.to_scipy

No I mean in the Legacy DOLFIN, not DOLFINX

This has already been answered at: How to access print assembled matrix from variational form - #2 by dokken

1 Like