My computer keeps freezing when running FreeFEM

Hello,

Whenever I run more intensive code my computer freezes. I am trying to solve an eigebvalue problem on geometry, and need to get to like 1000 eigenvalues with a couple hundred nodes on each side, so I expect it to take some time. When I run it with less accuracy or fewer eigenvales it’s goes through fine, but currently whenever it hits the couple hour mark everything just locks up.

Currently I edit code in the online compiler and the. Download the .edp file to run it locallly. Does anyone have any suggestions as to what is going on? I can also post code if that will help.

I have a pretty decent pc (16gb of RAM for example) and am not doing anything else. This could be machine side but it’s so consistent in how if fails I feel like something else is up.

Thank you for the help

Do you use parallel computing?

I don’t think so. How would I tell

Thank you for the response as well

If you use FreeFem++-mpi instead of FreeFem++, you do parallel computing.
The cost of the operations in an eigensolve increase nonlinearly. So it can be highly beneficial to use FreeFem++-mpi + EPSSolve (parallel eigensolver from SLEPc), instead of FreeFem++ and EigenValue.
If you share a minimalist script I can show you how easy it is to go parallel.

// Parameters
real sigma = 1; //value of the shift (ignore)
real a = 1./sqrt(3);   //length of bottom side
string lengthName = "306090";
int n = 25;   //numer of mesh points on each side
int nev = 1; //number of computed eigen values

// Mesh
border a0(t=0., .5){x=0; y=1.-t;}        //top half of left side
border a1(t=0., .5){x=0; y=.5-t;}        //bottom half of left side
border a2(t=0., .5){x=a*(1.-t); y=t;}    //bottom half of hypotenuse
border a3(t=0., .5){x= a*(.5-t); y=.5+t;}//top half of hypotenuse
border a4(t=0., .5){x=a*t; y=0.;}        //left half of bottom side
border a5(t=0., .5){x=a*(.5+t); y=0.;}   //right half of bottom side

//Freefem stuff. Builds mesh and declares function space. Stuff in this section from example.
mesh Th = buildmesh(a0(n) + a1(n) + a2(n)+ a3(n)+ a4(n)+ a5(n));
fespace Vh(Th, P2);
Vh u1, u2;

// Problem
// OP = A - sigma B ; // the shifted matrix
varf op (u1, u2)
	= int2d(Th)(
    dx(u1)*dx(u2)
	+ dy(u1)*dy(u2)
	- sigma* u1*u2
   )
+ on(a0,a1,a2,a3,a4,a5, u1=0)
;

varf b ([u1], [u2]) = int2d(Th)(u1*u2); //no boundary condition

matrix OP = op(Vh, Vh, solver=Crout, factorize=1); //crout solver because the matrix in not positive
 matrix B = b(Vh, Vh, solver=CG, eps=1e-20);

// important remark:
// the boundary condition is make with exact penalization:
// we put 1e30=tgv on the diagonal term of the lock degree of freedom.
// So take Dirichlet boundary condition just on $a$ variational form
// and not on $b$ variational form.
// because we solve $ w=OP^-1*B*v $

// Solve
real[int] ev(nev); //to store the nev eigenvalue


Vh[int] eV(nev); //to store the nev eigenvector

int k = EigenValue(OP, B, sym=true, sigma=sigma, value=ev, vector=eV,
	tol=1e-10, maxit=0, ncv=0);

// Display & Plot
for (int i = 0; i < k; i++){
	u1 = eV[i];

    real gg = int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1));
    real mm = int2d(Th)(u1*u1) ;
	cout << "lambda[" << i << "] = " << ev[i] << ", err= " << int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1) - (ev[i])*u1*u1) << endl;
	plot(eV[i], cmm="Eigen Vector "+i+" value ="+ev[i], wait=true, value=true);
}

Please put your whole code between brackets otherwise I can’t copy/paste it. It should look like this:

some FreeFEM script easily copy/paste-able;

Also, you may want to switch from Crout to sparsesolver in your definition of A.

1 Like
  1. still not copy/paste-able, I meant to say three single quotes ``` , not bracket {
  2. please just edit your post instead of adding a new one to the thread
  3. once you think you are done, please double check by copy/paste-ing what you have on your browser and make sure that it runs on your machine, then it mean it will run on mine as well! :smile:

Edit: I can see you are using the wrong symbol: ’ instead of `

Yep it runs on my machine. I usually crank up n and number of evalues and have a bunch of compuations, but it should put out a graph of an eigenfunction on the triangle

There it is lmao

Does the following script run on your machine?
It should if you have a complete FreeFEM installation, that is FreeFEM + PETSc.
It is parallel, but first, it’s best to check that it runs using the command:

FreeFem++-mpi script.edp -v 0 -wg

You should get the desired results, for example, here with n = 100 in the screenshot.

// Parameters
real sigma = 1; //value of the shift (ignore)
real a = 1./sqrt(3);   //length of bottom side
string lengthName = "306090";
int n = 25;   //numer of mesh points on each side
int nev = 1; //number of computed eigen values

// Mesh
border a0(t=0., .5){x=0; y=1.-t;}        //top half of left side
border a1(t=0., .5){x=0; y=.5-t;}        //bottom half of left side
border a2(t=0., .5){x=a*(1.-t); y=t;}    //bottom half of hypotenuse
border a3(t=0., .5){x= a*(.5-t); y=.5+t;}//top half of hypotenuse
border a4(t=0., .5){x=a*t; y=0.;}        //left half of bottom side
border a5(t=0., .5){x=a*(.5+t); y=0.;}   //right half of bottom side

//Freefem stuff. Builds mesh and declares function space. Stuff in this section from example.
mesh Th = buildmesh(a0(n) + a1(n) + a2(n)+ a3(n)+ a4(n)+ a5(n));
plot(Th);
func Pk = P2;
fespace Vh(Th, Pk);
Vh u1, u2;

// Problem
// OP = A - sigma B ; // the shifted matrix
varf op (u1, u2)
	= int2d(Th)(
    dx(u1)*dx(u2)
	+ dy(u1)*dy(u2)
   )
+ on(a0,a1,a2,a3,a4,a5, u1=0)
;

varf b ([u1], [u2]) = int2d(Th)(u1*u2)
+ on(a0,a1,a2,a3,a4,a5, u1=0)
; //no boundary condition

load "SLEPc"
Mat OP;
include "macro_ddm.idp"
createMat(Th, OP, Pk)
OP = op(Vh, Vh, tgv = -2,sym=1); //crout solver because the matrix in not positive
 matrix loc = b(Vh, Vh, tgv = -20, sym =1);
Mat B(OP, loc);


// important remark:
// the boundary condition is make with exact penalization:
// we put 1e30=tgv on the diagonal term of the lock degree of freedom.
// So take Dirichlet boundary condition just on $a$ variational form
// and not on $b$ variational form.
// because we solve $ w=OP^-1*B*v $

// Solve
real[int] ev(nev); //to store the nev eigenvalue


Vh[int] eV(nev); //to store the nev eigenvector

int k = EPSSolve(OP, B, values=ev, vectors=eV,sparams = "-st_type sinvert -eps_nev " + nev + " -eps_target " + sigma);

// Display & Plot
for (int i = 0; i < k; i++){
	u1 = eV[i];

    real gg = int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1));
    real mm = int2d(Th)(u1*u1) ;
	cout << "lambda[" << i << "] = " << ev[i] << ", err= " << int2d(Th)(dx(u1)*dx(u1) + dy(u1)*dy(u1) - (ev[i])*u1*u1) << endl;
	plot(eV[i], cmm="Eigen Vector "+i+" value ="+ev[i], wait=true, value=true);
}

I dont think I have the complete installation. Mine just says FreeFem ++ 4.6 > I also could not get the script to run.

OK, then you’ll have to update or at least make sure you have FreeFEM installed with PETSc (if you use the .exe or .deb from GitHub it is there by default). Can’t really help you otherwise.
Maybe just try to replace Crout by sparsesolver, this may be a small first improvement.

Ok i will go try and update that and see what happens. If after that the the code you gave me didnt work ill ping this thread again.

Thank you so much for the help