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

How to set the parameters of SLEPcEigenSolver() ?

+1 vote

Hi, everybody. I am a newer to fenics, so anyone's help will be greatful !

Run the below code, I got an error like this:

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

The source code is below,

from fenics import *

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)
solver.parameters["spectrum"] = "largest magnitude"
solver.parameters['solver'] = "power"
print solver.parameters.str(True)

print("begin...................................")
solver.solve(10)
print('the number of converged eigenvalues is :', solver.get_number_converged())
for i in range(10):
    r,c = solver.get_eigenvalue(i)
        print r,c
print("end.....................................")
asked Feb 27, 2017 by fanronghong FEniCS User (1,680 points)
edited Jun 27, 2017 by fanronghong

1 Answer

+1 vote
 
Best answer

Your error means that the iterative scheme you've set for SLEPc has failed to converge. You should consider carefully the implications of these methods on your generalised eigenvalue problem, and choose solvers accordingly to encourage convergence. Consider setting the option PETScOptions.set("eps_view") to see details of the solution process.

You can set solver parameters as you have in your code:

solver.parameters["spectrum"] = "largest magnitude"
solver.parameters['solver'] = "power"

Or you can directly set the PETSc/SLEPc options, e.g. using mumps as the direct solver for the spectral transformation (note the st_ prefix):

PETScOptions.set("st_ksp_type", "preonly")
PETScOptions.set("st_pc_type", "lu")
PETScOptions.set("st_pc_factor_mat_solver_package", "mumps")

These options are all documented in the PETSc and SLEPc documentation.

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

Thank you very much for your help!!!

But how could I check the type of matrix A, B in SLEPcEigenSolver(A, B)?
I mean whether A and B are Hermitian or not.

You can use A.is_symmetric(TOL) for a given tolerance. But you should be able to determine whether the matrix is Hermitian from the finite element formulation. I.e. are

$$ a(\cdot, \cdot) \text{ and } b(\cdot, \cdot) $$

sesquilinear and symmetric ?

...