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

unable to solve the eigenvalue problem

+1 vote

Hi, everybody

I am a newer to fenics. So everyone's answer is helpful to me. Thanks.

When I run the below code, I got an error below.

begin.......
('the number of converged eigenvalues is :', 0)
Traceback (most recent call last):
  File "test4.py", line 41, in <module>
    r,c = solver.get_eigenvalue(i)
  File "/usr/lib/python2.7/dist-packages/dolfin/cpp/la.py", line 4673, in get_eigenvalue
    return self._get_eigenvalue(i)
RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to extract eigenvalue from SLEPc eigenvalue solver.
*** Reason:  Requested eigenvalue (0) has not been computed.
*** Where:   This error was encountered inside SLEPcEigenSolver.cpp.
*** Process: 0
*** 
*** DOLFIN version: 2016.2.0
*** Git changeset:  unknown
*** -------------------------------------------------------------------------

Aborted (core dumped)

The full code is below,

from fenics import *
import numpy as np
import pdb

mesh = UnitCubeMesh(10, 10, 10)
cell = "tetrahedron"

P0 = FiniteElement('DG',cell,0)
P1 = FiniteElement('P',cell,1)
P3_vec = VectorElement('P',cell,1)
Nedelec_1st = FiniteElement('N1curl',cell,1)

element=MixedElement([P0,P1,P1,P3_vec,Nedelec_1st,P1])
V=FunctionSpace(mesh,element)

z,v,q,eta,deta,s=TestFunctions(V)
y,u,p,zeta,gamma,r=TrialFunctions(V)

# define the 2 bilinear forms
alpha=Constant(1.3)
beta=Constant(1.5)
a = y*z*dx-inner(grad(r),grad(v))*dx+inner(gamma,grad(q))*dx+\
        alpha*div(zeta)*div(eta)*dx+inner(curl(zeta),curl(eta))*dx+inner(curl(gamma),curl(eta))*dx+\
        inner(grad(r),eta)*dx+inner(grad(p),deta)*dx+\
        inner(curl(zeta),curl(deta))*dx-inner(grad(u),grad(s))*dx+\
        inner(zeta,grad(s))*dx
b=beta*u*z*dx-alpha*(y+div(zeta))*v*dx+inner(grad(alpha*beta*u),eta)*dx

# forming the eigenvalue problem
A=PETScMatrix()
B=PETScMatrix()
assemble(a, tensor=A)
assemble(b, tensor=B)

# define a solver of general eigenvalue problem
solver = SLEPcEigenSolver(A, B)
print("begin.......")
solver.solve(10)
print('the number of converged eigenvalues is :', solver.get_number_converged())
for i in range(5):
    r,c = solver.get_eigenvalue(i)
    print r,c
print("end.........")
asked Feb 8, 2017 by fanronghong FEniCS User (1,680 points)

Is the matrix A hermitian?

Thank you very much for your answer!!!

Yes, the matrix A is hermitian.

2 Answers

+2 votes
 
Best answer

If your problem is a generalised hermitian eigenvalue problem, be sure to set the parameters correctly.

solver = SLEPcEigenSolver(A, B)
solver.parameters["problem_type"] = "gen_hermitian"

Also consider other parameters for your problem.

print solver.parameters.str(True)

And set the appropriate spectral transform ksp and preconditioner through PETScOptions.set()

Eigenvalue problems as large and intricate as the one you've posted are non-trivial to solve. Any number of issues could arise which require a lot of investigation. If you haven't already, I suggest starting with a simple generalised eigenvalue problem such as the Helmholtz equation ensuring you can get it to work.

answered Feb 9, 2017 by nate FEniCS Expert (17,050 points)
selected Feb 9, 2017 by fanronghong

Thank you very much for your help!!!

Let me try it.

+1 vote

Hi there,

the issue probably is the

for i in range(5):

statement, because eigenvalues are numbered with positive integers, i.e. 1,2,3,...

I would simply try

for i in [1,2,3,4,5]:
answered Feb 8, 2017 by wilhelmbraun FEniCS User (2,070 points)

Addition: range(5) will return [0, 1, 2, 3, 4], hence the issue with the missing eigenvalue.

Thank you very much for your answer!!!

I tried your idea, but it's not work. And error message is below.

begin.......

('the number of converged eigenvalues is :', 0)
Traceback (most recent call last):
File "test4.py", line 40, in
r,c = solver.get_eigenvalue(i)
File "/usr/lib/python2.7/dist-packages/dolfin/cpp/la.py", line 4673, in get_eigenvalue
return self._get_eigenvalue(i)
RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to extract eigenvalue from SLEPc eigenvalue solver.
*** Reason: Requested eigenvalue (1) has not been computed.
*** Where: This error was encountered inside SLEPcEigenSolver.cpp.
*** Process: 0


*** DOLFIN version: 2016.2.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------

Aborted (core dumped)

And I think maybe the statement solver = SLEPcEigenSolver(A, B) is wrong, just maybe.
It seems like the code didn't compute the eigenvalues at all.

...