I have a question about different methods of calculation of a relation.
my relation is

fespace Xh(th,P2);
Xh U,F,GradJ;
real alpha;
GradJ=alpha*F+U;

I have F and U from previous solutions of PDE equations and just want to add them together with weight alpha.
now, I am confused if I write it as follow, answers are different. I don’t know which one is correct.

Probably the easiest thing to do is try a small mesh with known data.
The both expressions are fairly literal - The first one is just as written scaled F + U.
The second one integrates of the test functions it is the RHS for a FEM
problem in form Ax=b . I guess you probably want the first expression.

Actually my case is axisymmetric and I do the optimization. I was not sure to compute gradients for descent direction, should I use variational form (1st method) and multiply it by r (radius) or just use the second method. In non axisymmetric models, I used the method you proposed and worked.

I am not sure about the answer. I think if the radius is in the variational form ,then you cannot multiply with R outside the varf, but I do not know about the precise problem you are solving.