I’m trying to build a lumped mass matrix in Fenics and then perform some matrix operations on it (such as: invert it, perform matrix-matrix-multiplications, etc.). To this end, I need to be able to explicitly construct the matrix through the linear algebra backend in Fenics. A google search pointed me to
as_backend_type(…).mat()
So I wrote a test program which looks like this:
from dolfin import *
mesh = UnitSquareMesh(2,2)
V = VectorFunctionSpace(mesh, “CG”, 2)
v = TestFunction(V)
u = TrialFunction(V)
This gives me the following error message:
ERROR: could not import petsc4py!
Traceback (most recent call last):
File “test.py”, line 14, in
M_lumped_mat = as_backend_type(M_lumped).mat()
RuntimeError: Error when importing petsc4py
I’m using python3 and installed petsc & petsc4py (seemingly) without issues. Could someone point me in the direction of where I went wrong? Thank you!
Because dolfin when installed through the package manager comes with its own petsc and petsc4py installation.
If you want to use another build of petsc or petsc4py, you have to build dolfin from source, see: https://fenics.readthedocs.io/en/latest/installation.html#from-source