Confused about correct method

Dear all,

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.

varf vf(unused,v)=int2d(th)((alpha*F+U)*v);
gradJ[]= vf(0,Xh);

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.

1 Like

I think you just need to add the functions together.
I think the most efficient way is the following

GradJ[] = F[];
GradJ[] *= alpha;
GradJ += U[];

This way you are just adding and multiplying the vectors. If you do GradJ=alpha*F+U;, then the functions are interpolated.

2 Likes

Thanks aszaboa,

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.

I found that in the Stabfem repository, you can find the FreeFem implementation of various flow stability equations, which illustrate a lot of tricks. You might find the answer there; e.g., in SOURCES_FREEFEM/Newton_Axi.edp · master · StabFem / StabFem · GitLab

1 Like