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

Eigenproblem gives strange results

+6 votes

Hello everybody,

I try to solve an eigenproblem and therefore ran the example given at Eigensolver-Example on the UnitSquareMesh. This results in a strange solution where every other node value seems to have inverted signs like this for the first eigenfunction

0.00010193 -0.00070872 -0.00070872  0.00126459  0.00353581  0.00126459
-0.00178778 -0.00628004 -0.00628004 -0.00178778  0.00226874  0.00887621 ...

This results in a striped solution and is obviously not correct as it relates directly to the discretisation. Can anybody else reproduce this or even better knows what's going wrong.

I use the Ubuntu ppa on Ubuntu 13.04.

Thanks in advance,
Johannes

asked Aug 23, 2013 by jenom FEniCS Novice (690 points)

Just for completeness. I found a workaround for this behaviour. What you need to do is to load the dof2vertex map from your space and then invert every second value like this

dof2vert = space.dofmap().dof_to_vertex_map(mesh)
dofHalf = dof2vert[1::2]
eigenFun[dofHalf] = -eigenFun[dofHalf]

Hope, this helps.

Edit: Infact this only works for some meshes e.g. UnitSquareMesh(10,10) but not for others like UnitSquareMesh(11,11). I guess it has to do with the reordering of DoF in assemble which might be new since the example was written.

I would also be interested to understand why the sign switches in the coefficients occur. Ideas anyone?

from dolfin import *

# setup mesh, space and form
N = 5
mesh = UnitSquareMesh(N, N)
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
a = dot(grad(u), grad(v))*dx

# assemble and solve EVP
A = PETScMatrix()
assemble(a, tensor=A)
eigensolver = SLEPcEigenSolver(A)
eigensolver.solve()
r, c, rx, cx = eigensolver.get_eigenpair(0)

# setup and plot first eigenfunction
u = Function(V)
u.vector()[:] = rx
plot(u, title="EF", interactive=True)

Hi
It doesnt happen when I use CG with even degree like 2,4 etc
e.g. with
V = FunctionSpace(mesh, "CG", 2)
the mode shapes are plotting OK.
I am also interested in why eigenvectors flip sign when using CG of odd order.

Any ideas?

...