# Problem vs varf

**URL:** https://community.freefem.org/t/problem-vs-varf/3525
**Category:** General Discussion
**Created:** [September 29, 2024, 9:06pm UTC](https://community.freefem.org/t/problem-vs-varf/3525 "2024-09-29T21:06:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![PierreAntonetti](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@PierreAntonetti](https://community.freefem.org/u/PierreAntonetti)
#### Post date: [September 29, 2024, 9:06pm UTC](https://community.freefem.org/t/problem-vs-varf/3525/1 "2024-09-29T21:06:21Z")

</div>

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](https://community.freefem.org/uploads/short-url/64olBwC2iqizZxCX5UkANxrx9yX.mesh) (270 Bytes)

```auto
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);

```

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [September 30, 2024, 7:54am UTC](https://community.freefem.org/t/problem-vs-varf/3525/2 "2024-09-30T07:54:09Z")

</div>

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

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [September 30, 2024, 7:55am UTC](https://community.freefem.org/t/problem-vs-varf/3525/3 "2024-09-30T07:55:05Z")

</div>

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

---

<div class="post-metadata">

### Author: ![PierreAntonetti](https://avatars.discourse-cdn.com/v4/letter/p/f1d935/32.png) [@PierreAntonetti](https://community.freefem.org/u/PierreAntonetti)
#### Post date: [September 30, 2024, 2:51pm UTC](https://community.freefem.org/t/problem-vs-varf/3525/4 "2024-09-30T14:51:46Z")

</div>

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