Hi, everybody,
I'm newer to FEniCS. So anyone's answer is helpful and I appreciate your help.
When I use assemble(a,tensor=A)
, it's OK.
But when I use A=assemble(a)
, I get a MPI_Comm
error. The error message is below:
Traceback (most recent call last):
File "eigenvalue_problem.py", line 21, in <module>
eigensolver = SLEPcEigenSolver(A)
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/la.py", line 4549, in __init__
_la.SLEPcEigenSolver_swiginit(self, _la.new_SLEPcEigenSolver(*args))
TypeError: in method 'new_SLEPcEigenSolver', argument 1 of type 'MPI_Comm'
Aborted (core dumped)
The mesh file can be got from: https://fenicsproject.org/pub/data/meshes/
The source code is :
from __future__ import print_function
from dolfin import *
# Define mesh, function space
mesh = Mesh("box_with_dent.xml.gz")
V = FunctionSpace(mesh, "Lagrange", 1)
# Define basis and bilinear form
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(v))*dx
# Assemble stiffness form
A = PETScMatrix()
#The below statement is OK.
#assemble(a, tensor=A)
#But using the below command replacing assemble(a,tensor=A) will cause MPI_Comm faulty.
A=assemble(a)
# Create eigensolver
eigensolver = SLEPcEigenSolver(A)
# Compute all eigenvalues of A x = \lambda x
eigensolver.solve()
# Extract largest (first) eigenpair
r, c, rx, cx = eigensolver.get_eigenpair(0)
print ("Largest eigenvalue: ", r,c)