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

Solving a complex eigenvalue problem

0 votes

Hello,

In a previous question of mine I asked if I could write an UFL form with complex coeffcients and the answer was negative so I decided to write two UFL forms corresponding to the real and imaginary parts of my problem. With this approach I obtain and assemble two real matrixes.
Is it possible, remaining in my FEniCS/C++ code, to sum or merge them into one matrix (thus obtaining the complete complex matrix of my problem) and then call an external solver capable of dealing with complex eigenproblems, possibly with some other C++ library?

Thanks for any advice

asked Nov 20, 2015 by ededonati FEniCS Novice (200 points)

1 Answer

0 votes

I am not sure exactly what you are trying to achieve, but some points:

If you want to deal with the matrices yourself you can do so in Python using petsc4py or even numpy, and I am confident that there is some C++ equivalent (using PETSc directly?). However...

I am not sure if I understand the 'to sum or merge them into one matrix' part. Instead of complex eigenvalue problem you should have two real ones, one for the real part and one for the imaginary part, where there might be some coupled terms present (i.e. dependency on the imaginary solution in the evp of the real part or vice versa). The best way to deal with this (Python API, you'll have to look for the C++ equivalent)

V = FunctionSpace(mesh, 'CG' 1)
Vcomplex = V * V
ureal, uimag = TrialFunction(Vcomplex)
vreal, vimag = TestFunction(Vcomplex)

Then you can write the weak form with both real and imaginary parts together, where you use vreal for the real terms and vimag for the imaginary ones. When you assemble, it will automatically result in 1 matrix.

answered Nov 23, 2015 by maartent FEniCS User (3,910 points)

Thanks for your answer, but my problem is a bit different. I apologize if I was not clear when trying to explain it.

I have to solve an eigenvalue problem of the form:
lambda M x = A x
where A is a complex matrix A = Ar + i Ai

What I understood so far is that the only solution to assemble the matrix with an UFL form is to write one for Ar and one for Ai (maybe even in the same UFL file). The problem is: once I have Ar and Ai in my C++ code, how can I solve the eigenvalue problem?

I hope my explaination is not ambiguous
Thanks for any further advice

The way you want to solve your complex eigenproblem requires a solver that can handle complex numbers, and your solution will be a complex vector [a1 + i b1, a2 + i b2, ...]. It should be possible, although I have no experience on how to do it. My guess would be to use PETSc to add Ar and Ai into a new, complex matrix and then call the SLEPc eigensolver directly in your C++ code.

However, if you want to avoid all that and stay within the dolfin-ecosystem, you can try to get the solution in the form [a1, a2, ..., b1, b2, ...] with the method I outlined above (and perhaps reconstruct the complex numbers later if you need them).

Thanks for your advice,

It is no problem for me to use PETSc or SLEPc. My doubts were focused on using a solver that can handle complex numbers. From what you have written I understand that SLEPc eigensolver is capable to do it.

Thanks for your answer

hi, i am trying to solve a complex eigenvalue problem now. Just wondering how to use PETSc to add Ar and Ai into a new, complex matrix.

...