# Diffrence in results between varf and problem statment

**URL:** <https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288>\
**Category:** General Discussion\
**Created:** [June 4, 2024, 6:50pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288 "2024-06-04T18:50:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Walid](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/walid/32/2477_2.png) [@Walid](https://community.freefem.org/u/Walid)\
**Post date:** [June 4, 2024, 6:50pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/1 "2024-06-04T18:50:13Z")

</div>

I am tryin to solve PDE and need to use PETSc and need yo know if using it with problem statement or should I use varf statement.  
the problem is when I use varf statement the results differs than using problem statement and I am sure that results obtained from problem statement is correct

hereunder is the code for defining the PDE in two different statements and the remain code is the same  
1-  
problem HydrodynamicNn(Nn, v3) = int2d(Th)(Nn_v3  
+(Dn_dt\*(grad(Nn)'_grad(v3)))  
+((-Wnx \* dx(Nn) + -Wny \* dy(Nn))dtv3))  
-int2d(Th)(Nnold_v3)  
-int2d(Th)(Sn_v3_dt)  
+on (needle, Nn = 0)  
//solve  
HydrodynamicNn;

2-  
varf HydrodynamicNn(Nn, v3) = int2d(Th)(Nn_v3  
+(Dn_dt\*(grad(Nn)'_grad(v3)))  
+((-Wnx \* dx(Nn) + -Wny \* dy(Nn))dtv3))  
-int2d(Th)(Nnold_v3)  
+int2d(Th)(Sn_v3_dt)  
+on (needle, Nn = 0);  
//constructing the matrices  
matrix AN = HydrodynamicNn(Ve,Ve, solver = UMFPACK, factorize =0) ;  
real [int] bN = HydrodynamicNn(0 ,Ve) ;

//Solve  
Nn = AN^-1\*bN ;

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [June 5, 2024, 4:40am UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/2 "2024-06-05T04:40:29Z")

</div>

You have to be careful with signs of the rhs when passing from `problem` to `varf`. see discussion in [this thread](https://community.freefem.org/t/change-of-sign-in-linear-part-of-variational-problem-varf-vs-problem/2984/2)

---

<div class="post-metadata">

**Author:** ![Walid](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/walid/32/2477_2.png) [@Walid](https://community.freefem.org/u/Walid)\
**Post date:** [June 5, 2024, 3:27pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/3 "2024-06-05T15:27:57Z")

</div>

Thank you very much for you attention and reply  
but I thing the sings are correct in problem statement it is negative ( -int2d(Th)(Sn_v3_ dt)  
and in varf statement it is positive ( +int2d(Th)(Sn_v3_ dt))

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 5, 2024, 3:57pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/4 "2024-06-05T15:57:00Z")

</div>

You cannot use `problem`. You must define a `varf` in order to build the `Mat` object for PETSc. See the [examples](https://github.com/FreeFem/FreeFem-sources/tree/master/examples/hpddm).

---

<div class="post-metadata">

**Author:** ![Walid](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/walid/32/2477_2.png) [@Walid](https://community.freefem.org/u/Walid)\
**Post date:** [June 5, 2024, 4:04pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/5 "2024-06-05T16:04:50Z")

</div>

Thank you for your attention and reply  
another question and forgive me if it so basic  
the default solver used when write problem statement is the same as writing varf statement (wit out mentioning and solver like below)

problem HydrodynamicNn(Nn, v3)  
varf HydrodynamicNn(Nn, v3)

what I am trying to say that the above two statements uses the same solver ?

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 5, 2024, 4:18pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/6 "2024-06-05T16:18:09Z")

</div>

Yes, but the way the serial FreeFEM solvers work is different from the way they work in PETSc. Please spend some time working through the examples and then follow up if you have additional questions.

---

<div class="post-metadata">

**Author:** ![Walid](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/walid/32/2477_2.png) [@Walid](https://community.freefem.org/u/Walid)\
**Post date:** [June 5, 2024, 5:36pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/7 "2024-06-05T17:36:51Z")

</div>

Hello Chris  
Thank you again for your time  
attached the code the problem now when I change problem to varf (and keep in mind the sign also of the right hand side change) I do not get a correct results

[new 1.edp](https://community.freefem.org/uploads/short-url/5FAYdRoJS7k3tKO9a3TWeQcbGkd.edp) (6.7 KB)

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 5, 2024, 5:50pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/8 "2024-06-05T17:50:38Z")

</div>

I suggest that you start with a MWE (see the examples folder) and then gradually increase the complexity until you understand your problem.

---

<div class="post-metadata">

**Author:** ![Walid](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/walid/32/2477_2.png) [@Walid](https://community.freefem.org/u/Walid)\
**Post date:** [June 10, 2024, 5:05pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/9 "2024-06-10T17:05:34Z")

</div>

> [@cmd](#):
>
> MWE

What is MWE ?  
I am sorry I am totally new with this program

---

<div class="post-metadata">

**Author:** ![cmd](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/cmd/32/67_2.png) [@cmd](https://community.freefem.org/u/cmd)\
**Post date:** [June 10, 2024, 5:16pm UTC](https://community.freefem.org/t/diffrence-in-results-between-varf-and-problem-statment/3288/10 "2024-06-10T17:16:32Z")

</div>

> **[Minimal reproducible example](https://en.wikipedia.org/wiki/Minimal_reproducible_example)**
>
> In computing, a minimal reproducible example (abbreviated MRE) is a collection of source code and other data files which allow a bug or problem to be demonstrated and reproduced. The important feature of a minimal reproducible example is that it is as small and as simple as possible, such that it is just sufficient to demonstrate the problem, but without any additional complexity or dependencies which will make resolution harder.
> A minimal reproducible example may also be referred to as a reprex...
