Missing the first eigenVector/eigenvalue

Hello !
I’m currectly using FreeFEM++ to compute electronic structures.
I wrote a FreeFREM++ code supposed to compute the lowest eigenvalues and eigenfunctions of the Schrödinger equation in 2D, that is to solve the elliptic eigenvalue problem

  • \frac 12 \Delta u(x) + V(x) u(x) = E u(x) on a square with periodic boundary, where V is a given function.

The eigenvalues (E_n) are ranked in nondecreasing order : E_1 \le E_2 \le E_3 …

Following the example of acoustics I found in Acoustics , I used the following code lines to solve the resulting generalized eigenvalue problem:

matrix K= rigidite(Vh,Vh,solver=Crout,factorize=1);
matrix M= masse(Vh,Vh,solver=CG,eps=1e-20);

// Computation of the 5 lowest eigenvalues

int nev=5;
real[int] ev(nev);
Vh[int] eV1 (nev);
real sigma= 0.0;
real scale=10;
int k=EigenValue(K,M,sym=true, sigma=sigma, value=ev,vector=eV1,tol=1e-10,maxit=0,ncv=0);

cout << "First eigenvalue : " << ev[0] << endl;
cout << "Second eigenvalue : " << ev[1] << endl;
cout << "Third eigenvalue : " << ev[2]<< endl;
cout << "Fourth eigenvalue : " << ev[3] << endl;
cout << "Fifth eigenvalue : " << ev[4] << endl;

Surprisingly, it seems that the code misses the lowest eigenvalue (ev[0] \simeq E_2).

Does someone know how to fix this problem?

Thank you in advance!

Grégoire

I’d recommend that you use SLEPc instead of ARPACK, see, e.g., FreeFem-sources/schrodinger-square-well-1d-SLEPc.edp at develop · FreeFem/FreeFem-sources · GitHub or FreeFem-sources/schrodinger-harmonic-oscillator-2d-SLEPc.edp at develop · FreeFem/FreeFem-sources · GitHub. It’s much easier to debug things there.

Hello prj and thank you for your answer !

I tried to use your example but couldn’t make it work because of an unsuccessful installation of PETSc & SLEPc on my virtual machine.
So I tried to make it work on the cluster of my workplace, where FreeFEM++ is compiled without SLEPc/PETSc in /3rdparty folder. (I need to sudo make install some files, but don’t have rights to sudo.
I tried to load my own installation of SLEPc/PETSc : the library seems to be loaded but I can’t call a single function of it.
Example given :
load " “/home/…/SLEPc.so” "
load " “/home/…/PETSc.so” "

If I try to call for example the function EPSSolve, I’m told that the identifier EPSSolve doesn’t exist.
Maybe isn’t it possible to load a library this way ?

Thank you in advance !

Grégoire

You don’t need to use sudo if you build FreeFEM with a prefix. You must do that when on a cluster. Please configure and install FreeFEM correctly, see, e.g., README.md, and then try again.

Hello prj !
Thanks a lot for your answer. I followed the README.ME instructions and it seems to work.

Thank you again and have a good afternoon.

Grégoire