Option "rhsvarf" for on()

This proposal is related to the discussion Behavior of varf with rhs and on()
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

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

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

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.

Do you have a proper use case?

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:

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

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?

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.

“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.

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?

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.

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.