# Variable formulation error

**URL:** <https://community.freefem.org/t/variable-formulation-error/3976>\
**Category:** General Discussion\
**Created:** [June 19, 2025, 5:01pm UTC](https://community.freefem.org/t/variable-formulation-error/3976 "2025-06-19T17:01:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![goutham2023](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/goutham2023/32/1759_2.png) [@goutham2023](https://community.freefem.org/u/goutham2023)\
**Post date:** [June 19, 2025, 5:01pm UTC](https://community.freefem.org/t/variable-formulation-error/3976/1 "2025-06-19T17:01:43Z")

</div>

Hi FF Community,

I have attempted to convert a gas flow problem into a varf formulation, but there seems to be an error that’s resulting in incorrect solutions. I’ve attached a screenshot of the varf statement along with the code.

Could you please take a look and let me know what might be wrong?

Thank you!

 ![Screenshot from 2025-06-20 09-28-21](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/7/737095915ca006f3250a913975a9f1aef490e77b.png)  
[porepcheckpll.edp](https://community.freefem.org/uploads/short-url/dUBbL6wQI1NJQZnDUONyW1tw5Sd.edp) (3.2 KB)

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [June 20, 2025, 3:33pm UTC](https://community.freefem.org/t/variable-formulation-error/3976/2 "2025-06-20T15:33:19Z")

</div>

In your varf for the right-hand side `varf gasflow2` the two last lines need to te removed (they correspond to nothing in `problem gasflow`, which is your working reference if I understand well).  
You need also to put the boundary conditions in `gasflow2`. This gives

```auto
varf gasflow2(pr, q) =
    int1d(Msh)(prold * idt * phi * q / (T * R))
  +on(1,pr=200000)
  +on(2,pr=100000);

```

---

<div class="post-metadata">

**Author:** ![goutham2023](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/goutham2023/32/1759_2.png) [@goutham2023](https://community.freefem.org/u/goutham2023)\
**Post date:** [June 22, 2025, 7:10am UTC](https://community.freefem.org/t/variable-formulation-error/3976/3 "2025-06-22T07:10:45Z")

</div>

Thank you, it is working fine. What should we consider when applying Dirichlet and Neumann boundary conditions in varf statements?

---

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [June 22, 2025, 11:01am UTC](https://community.freefem.org/t/variable-formulation-error/3976/4 "2025-06-22T11:01:21Z")

</div>

The general rule is that you separate

- the terms that depend linearly on the unknown (your gasflow1), it defines the matrix of the system,
- the terms that do not depend on the unknown (your gasflow 2), it defines the right-hand side for the linear system.

The only special thing is for Dirichlet boundary conditions with on(), for example consider `+on(1,pr=200000)`. You have to understand that it contains two parts:

- one part for the matrix, it is the `pr=` (together with the info of label=1) that says which dof is concerned by the Dirichlet BC. It will modify the corresponding line of the matrix.
- one part for the right-hand side, it is the `=200000` (together with the info of label=1). It puts the value `200000` in the corresponding coordinate of the right-hand side (the index is the index of the line of the matrix in the previous coment).

Thus you have to put Dirichlet BC in both gasflow1 and gasflow2 in order to give all the data correctly.  
But for example if you set `+on(1,pr=0)` in gasflow1, the result is still correct because it takes only the part `pr=`.

You can look at

> **[FreeFEM-documentation.pdf](https://doc.freefem.org/pdf/FreeFEM-documentation.pdf)**
>
> 33.85 MB

p. 223-224
