Lagrange multiplier for Dirichlet boundary condition

Yes, since Th is distributed in the buildDmesh() call.

1 Like

Hi,

real[int] Af = af(0,Sh);

Mat M=[[UU, UP', UA'],
       [UP, 0,     0],
       [UA, 0,     0]];


int undof = Vh.ndof;
int pndof = Ph.ndof;
int andof = Sh.ndof;
int tndof = undof + pndof + andof;
/*
int undof = UU.n;
int pndof = PP.n;
int andof = AA.n;
int tndof = undof + pndof + andof;
*/
real[int] f(tndof);

f(0:undof + pndof - 1) = 0;
f(undof + pndof : tndof - 1) = Af;
real[int] fnew;
ChangeNumbering(M, f, fnew);

real[int]  sol = M^-1*fnew;

Can I create my FreeFem vector f first, then use my big martrix M to convert it to a PETSc vector fnew, as done above,
finally, solve it by sol = M^-1*fnew; ?

You cannot with M because it’s missing some diagonal terms. However, see, e.g., oseen-2d-PETSc.edp, you could do ChangeNumbering([UU, PP, AA], [rhsU, rhsP, rhsA], rhsPETSc);.
Also note that if you use the ^-1 syntax, your vector should be in FreeFEM numbering, not PETSc numbering, so there is no need for ChangeNumbering()

My matrix is a nested block matrix like

Mat M=[[UU, UP', UA'],
       [UP, 0,     0],
       [UA, 0,     0]];

Can I still use syntax M^-1 *f with f being FF numbering?

I notice FF numbering has the overlapped nodes, which then has more degrees of freedom than PETSc numbering, is this OK?

Yes, it should be OK. Or you can use KSPSolve(M, rhsPETSc, solPETSc).

Thank you. I have tried this using two cores, but it has an error of

malloc(): invalid size (unsorted)
malloc(): invalid size (unsorted)

stokes_lagrange_parallel_4.edp (3.8 KB)

There is no problem of using one core.

What do you get with a FreeFEM compiled with debugging, i.e., what I told you to do since the beginning?

Just look at stokes-block-2d-PETSc.edp, it’s clear from the name passed to the argument fields that it should be a vector in PETSc numbering. Yet, your are supplying a vector in FreeFEM numbering…

Yes, I tried to debug, but my machine does not allow me to do this as shown bellow


, sorry.

Finally it works – FF vector for the right-hand side and PETSc vector for the fields.

Thank you for all your help and your patience. I feel I have asked too many questions and I am sorry for this. I post the final version of this code here:
stokes_lagrange_parallel_4.edp (3.9 KB)
in case it will be useful for someone else.

Thanks again for all your help @prj !

No problem, glad it’s working. Hopefully the next questions will be more challenging! :slightly_smiling_face:

1 Like