Problem vs varf

Hello

I’m facing a problem I can’t understand when using varf instead of problem.
Here a very sample script which solve the poisson equation using adpatation.
The script works with problem but crash after the first adaptation iteration when using varf

Is there something wrong ?

Thanks.

temp.mesh (270 Bytes)

load "msh3"
mesh Th = readmesh("temp.mesh");
fespace Ph(Th, P1);
Ph u, v;
varf Poisson(u, v, solver=sparsesolver, eps=1.e-6)
	= int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v))
	+ int1d(Th)(u*v)
	- int1d(Th)(v)
;
matrix A;
real[int] rhs(Ph.ndof);
real error = 0.1;
// Adaptmesh loop
for (int i = 0; i < 10; i++){
       cout<<"Iter="<<i+1<<endl;
	rhs.resize(Ph.ndof);	
	A = Poisson(Ph, Ph, tgv = -1);
	rhs = Poisson(0,  Ph, tgv = -1);
	set(A, solver=sparsesolver, tgv=-1, eps=1e-6);
	u[] = A^-1*rhs;
	
    Th = adaptmesh(Th, u, err=error);
    error = error/2;
    cout<<"error="<<error<<endl;
}
exit(0);

Why do you have a minus sign in front of your linear form?

Also, you need to resize u after adaptation, like u = 0

Yes, I forgot u=0 !
Yes it’s a + instead of - :wink: (i didn’t modified from the problem formulation)
Thanks