Preconditioner for PETSc Mat

Deat all,

How to specify a block preconditioner in PETSc. For example, specify preconditioner
P=
A 0
0 M
for solving Kx=b, with
K=
A B
B’ 0

Best,
Yongxing.

1 Like

You can use FieldSplit preconditioner in PETSc and refer to those examples with the “fieldsplit” keyword in FreeFEM.

There is also a general introduction to fieldsplitting in FreeFEM there.

@zhaog6 @prj
Thank you both very much. I will look at this later.

@prj
Dear @zhaog6 ,
Thanks for your help! I have tried the “fieldsplit”, however it’s easy to come across a problem.
The first step works fine, and both velocity and pressure field are correct. However, in the second step, the solver complains: To use Schur complement preconditioner you must have exactly 2 fields…, which I believe it should have 2 fields, because the first step works fine and the matrix has the same structure in the second step-- really strange.


Ths_cylinder.mesh (373.3 KB)
Th_cylinder.mesh (639.7 KB)
fsi_3d_vector.edp (6.2 KB)

Do you have any idea?
BTW, the direct LU solver has no problem.

Best,
Yongxing.

You are probably calling set(..., sparams = "...") multiple times on the same matrix.

@prj
I did try to put A=fluid(…) and set (…, sparams=…) outside the loop, however I came across other issues. A related question is :

If the mesh Ths is moved , should I call
transferMat(Th, Pk, A, Ths, Pk, B, P)
again and again (inside the time loop)?

Both Th and A are static, but the boundary condition (inlet velocity) depends on time, should I put assembly of A outside the time loop?

@zhaog6 @prj
Indeed, I really want to call set(…) only once (outside the time loop). However, when I arrange the following code just outside the time loop:

Mat A,B;
{
macro def(i)[i, i#B, i#C, i#D]//
macro init(i)[i, i, i, i]//
createMat(Th, A, Pk)
createMat(Ths, B, Pk)
}
and

Mat P;
transferMat(Th, Pk, A, Ths, Pk, B, P)

inside the loop.

I came across the following error:

I have no idea which array size is 1? all arrays do have a size of 4.
fsi_3d_vector_opti.edp (6.0 KB)