# Option "rhsvarf" for on()

**URL:** <https://community.freefem.org/t/option-rhsvarf-for-on/3404>\
**Category:** Feature Request\
**Created:** [July 18, 2024, 2:12pm UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404 "2024-07-18T14:12:49Z")\
**Posts on this page:** 9\
**Page:** 1

<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:** [July 18, 2024, 2:12pm UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/1 "2024-07-18T14:12:49Z")

</div>

This proposal is related to the discussion [Behavior of varf with rhs and on()](https://community.freefem.org/t/behavior-of-varf-with-rhs-and-on/3248)  
I think it would be useful to have a new option “`rhsvarf`” (=true or false)  
for the `on()` tool that sets Dirichlet BC.

– If `on()` is used in the context of “`solve`” or “`problem`”, the option has no effect, and the behavior is the present one.

– The default value of `rhsvarf` would be “true”, in this case the behavior of `on()` is the present one. This means that when used within “`varf`”, the imposed value (i.e. `g` for “`on(1,u=g)`” ) is interpreted to the right-hand side.  
Ex

```auto
varf test(u,v)
=int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v))
-int2d(Th)(a*v)
+on(1,u=g)
;

```

Then `tab=test(0,Vh);` sets `tab` to `+g*tgv` (additionally to the `-int2d(Th)(a*v)` terms)

– Setting `rhsvarf=false` would imply that when used within “`varf`”, the imposed value `g` is interpreted in the left-hand side (thus changing its sign).  
For the previous example it means that  
`tab=test(0,Vh);` sets` tab` to `-g*tgv` (additionally to the `-int2d(Th)(a*v)` terms)

As a consequence, both codes

```auto
solve prob(u,v)
=int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v))
-int2d(Th)(a*v)
+on(1,u=g)
;
solprob=u[];

```

and

```auto
varf test(u,v)
=int2d(Th)(dx(u)*dx(v)+dy(u)*dy(v))
-int2d(Th)(a*v)
+on(1,u=g,rhsvarf=false)
;
matrix A=test(Vh,Vh);
tab=test(0,Vh);//compute the left-hand side
tab=-tab;//transform it into right-hand side
sol=A^-1*tab;

```

would give the same solutions `solprob` and `sol`.

---

<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:** [July 19, 2024, 5:49am UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/2 "2024-07-19T05:49:06Z")

</div>

Do you have a proper use case?

---

<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:** [July 19, 2024, 9:52am UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/3 "2024-07-19T09:52:28Z")

</div>

I would use it all the time, because I don’t want to ask myself what is the right sign each time I use on()! Indeed the present way it works is a source of error for me.  
An example where it would really simplify the coding is when I use a macro to define boundary conditions:

```auto
macro BCond +int1d(Th,2)(u1*N.x+u2*N.y)+on(3,u1=1.)+on(1,4,u1=0.,u2=-1.)//boundary conditions

```

Then I call `BCond` in many places all along the code, some involving `problem`, some involving `varf`

---

<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:** [July 19, 2024, 10:19am UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/4 "2024-07-19T10:19:15Z")

</div>

If you don’t want to ask yourself what is the proper sign, why do you switch between `varf` and `problem` and not just stick to a single type?

---

<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:** [July 19, 2024, 10:23am UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/5 "2024-07-19T10:23:23Z")

</div>

Also, what kind of guarantees do we have that people will never forget `tab=-tab;//transform it into right-hand side` when needed? You are asking for a way to let users shoot themselves in the foot.

---

<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:** [July 19, 2024, 11:59am UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/6 "2024-07-19T11:59:07Z")

</div>

“Why do you switch between varf and problem and not just stick to a single type?”  
Each of them has its advantages : problem is more simple, and varf has more capabilities (but needs more code lines)

“You are asking for a way to let users shoot themselves in the foot.”  
The issue of not forgetting the minus sign is already present concerning linear terms coming from `int2d`, as in my basic example.  
This sign is obviously related to considering right-hand sides (solving Ax=b) or left-hand sides (solving Ax+b=0).

I think that `rhsvarf=true` is adapted to the use of a two `varf`, one for the bilinear terms and one for the linear terms, whereas  
`rhsvarf=false` is adapted to the use of a single `varf` with bilinear and linear terms in it.

---

<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:** [July 19, 2024, 12:20pm UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/7 "2024-07-19T12:20:59Z")

</div>

> [@fb77](#):
>
> The issue of not forgetting the minus sign is already present concerning linear terms coming from `int2d`

What does that mean? If you know the proper definition of a `varf`, how could you be confused by the sign in front of the linear terms?

---

<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:** [July 19, 2024, 12:43pm UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/8 "2024-07-19T12:43:10Z")

</div>

There is no confusion: it follows that one needs to write `tab=-tab;` because we solve Ax+b=0, and this is not a difficulty.  
I am sorry to bother you, I see that you do not like my proposal.

---

<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:** [July 19, 2024, 1:00pm UTC](https://community.freefem.org/t/option-rhsvarf-for-on/3404/9 "2024-07-19T13:00:43Z")

</div>

You are not bothering me, this is a difficult (and frequent) issue, so it’s always worthwhile discussing this. That being said, you are correct, I don’t think this change would be useful for common users of FreeFEM (I personally never teach about `problem`, always `varf`, so there is less room for confusion). But if you make a merge request and find someone that would be OK to merge this, I won’t object.
