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

Eigenvalue-problem causing MPI_Comm error

0 votes

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)
asked Nov 8, 2016 by fanronghong FEniCS User (1,680 points)
edited Nov 8, 2016 by fanronghong

1 Answer

+1 vote
 
Best answer

Hi, SLEPcEigensolver requires A to be a PETScMatrix object. Doing assemble(a, tensor=A) where A=PETScMatrix() you are filling in the object of right type. On the other hand A=assemble(a) points A to the result of assemble(a), i.e. a Matrix class object (try print(type(A)))

answered Nov 8, 2016 by MiroK FEniCS Expert (80,920 points)
selected Nov 9, 2016 by fanronghong

Thank you very much. I got your point and I think you're right.
But sometimes when I use "assemble(a ,tensor=A)", I get a "segmentation error".
Another question: how to transform Matrix objects to PETScMatrix?

I appreciate your help very much!!!

...