Access matrix element

Dear all,

I can understand we can create the system matrix in FreeFEM++, my question is:
Can we modify the element of the matrix, such as putting a penalty (a large number) on the diagonal for a specific degree of freedom?

Best,
Yongxing.

https://doc.freefem.org/tutorials/heatEquationOptimization.html

Thank you, but this is still operating the whole matrix rather than a particular element of the matrix. I am thinking a penalty method to enforce Drichlet BC at a point?

Can you send me the copy of your freefem code
and the specific point?

LidDrivenCavityDisc.edp (4.4 KB)
Thanks very much for your help Daoudi.
Can you please fix the velocity (u,v)=(0,0) at point (0.6, 0.5) on mesh Th – expecting that the solid disc would keep rotating stably without shifting away?
Best,
Yongxing.

I am not 100% sure but here is what I would do (supposing that (0.6, 0.5) is a node of your mesh):

I did not look in details your script, but let’s assume we want to modify the matrix Aadj to impose a condition on the first component u (it would then be easy to do the same for other components) where Aadj is defined by:
fespace RhAdj(Th,[P2,P2,P2,P2,P1,P1]);
varf NSAdj([u,v,uhat,vhat,p,phat],[uh,vh,uhath,vhath,ph,phath]) = ...;
matrix Aadj = NSAdj(RhAdj,RhAdj,tgv=tgv);

The question is which entry (I,I) of the matrix should we modify?

int I; // index in the matrix corresponding to (0.6, 0.5) --> to find

Let’s do the following:

fespace Vh(Th,P2);
Vh xx = x, yy=y;
RhAdj [w1x, w2x, s1x, s2x, wpx, spx] = [xx,0,0,0,0,0];
RhAdj [w1y, w2y, s1y, s2y, wpy, spy] = [yy,0,0,0,0,0];

for (int k = 0; k < w1x[].n; ++k)
{
  if (w1x[][k] == 0.6 && w1y[][k]=0.5)
  {
    I = k;
  } 
}

And that should do it!

Thank you very much! I will try this out.
Best,
Yongxing.