Solver for unsteady N-S equation

Hi everyone,
This post is out of such reason: I am not familiar with solvers/preconditioners and it may take some time for me to harness them.
As the mesh scale grows, the computation gets slower. Are there easy adjustments to -pc_type lu -ksp_type preonly to improve the efficiency? Or is it a must to implement a specific preconditioner for a certain problem?

In some posts the mAL preconditioner is mentioned, is mAL also okay with unsteady problem? If so, maybe I can mimic the example natural-convection-fieldsplit-2d-PETSc.edp.

The 2D mesh could be up to 3000*3000(square) or even more with [P2,P2,P1] vectorial elements, will 128 cores be sufficient for such problem scale?

Best regards,
H.Weng

If it’s a 2D problem, something not too fancy may work out of the box. You could simply try -ksp_type gmres -pc_type asm -sub_pc_type lu.

Thanks for your quick reply,
The solver is now set(TS, sparams = "-ksp_type gmres -pc_type asm -sub_pc_type lu -ksp_view_final_residual");.
Unfortunately I got
TSStep has failed due to DIVERGED_STEP_REJECTED
after first step.

Does the linear solver converge?


The terminal is like this, the first line is the computation for the initial field. And then the TS routine for N-S and temperature, actually the thermal equation called another TSSolve in the TSSolve routine of N-S equation.
Should I upload the code?

Ah, try to add -sub_pc_factor_mat_solver_type mumps.

Now it is set(TS, sparams = "-ksp_type gmres -pc_type asm -sub_pc_type lu -ksp_view_final_residual -sub_pc_factor_mat_solver_type mumps");
and it won’t diverge at first step, but after several steps it will diverge.
I tried to use a smaller dt, and dt is finally turn to 3.8147e-08.

0 TS dt 0.01 time 0.
N-S equation solved, solve the thermal equation,
0 TS dt 0. time 0.
thermal equation solved, solve the next step
KSP final norm of residual 8.16106e-09
KSP final norm of residual 3.86178e-14
KSP final norm of residual 5.17033e-09
KSP final norm of residual 1.71385e-14
1 TS dt 0.01 time 0.01
N-S equation solved, solve the thermal equation,
0 TS dt 0.01 time 0.
KSP final norm of residual 7.9199e-32
1 TS dt 0.01 time 0.01
thermal equation solved, solve the next step
KSP final norm of residual 2.52215e-08
KSP final norm of residual 1.5837e-13
2 TS dt 0.01 time 0.02
N-S equation solved, solve the thermal equation,
0 TS dt 0.01 time 0.
KSP final norm of residual 7.40135e-25
1 TS dt 0.01 time 0.01
thermal equation solved, solve the next step
KSP final norm of residual 3.84135e-08
KSP final norm of residual 4.43181e-13
3 TS dt 0.01 time 0.03
N-S equation solved, solve the thermal equation,
0 TS dt 0.01 time 0.
KSP final norm of residual 1.12881e-24
1 TS dt 0.01 time 0.01
thermal equation solved, solve the next step
KSP final norm of residual 7.68258e-09
KSP final norm of residual 8.80407e-14
4 TS dt 0.01 time 0.04
N-S equation solved, solve the thermal equation,
0 TS dt 0.01 time 0.
KSP final norm of residual 1.34192e-24
1 TS dt 0.01 time 0.01
thermal equation solved, solve the next step
KSP final norm of residual 3.08425e-13
KSP final norm of residual 3.09537e-16
KSP final norm of residual 3.93751e-14
KSP final norm of residual 3.92473e-15
KSP final norm of residual 1.00479e-14
KSP final norm of residual 5.35912e-14
KSP final norm of residual 5.24062e-12
KSP final norm of residual 2.05859e-11
KSP final norm of residual 3.92306e-11
KSP final norm of residual 8.81865e-12
KSP final norm of residual 1.01131e-12
KSP final norm of residual 1.99914e-14
KSP final norm of residual 1.60835e-19
5 TS dt 3.8147e-08 time 0.04
N-S equation solved, solve the thermal equation,
0 TS dt 3.8147e-08 time 0.
KSP final norm of residual 1.46592e-24
1 TS dt 3.8147e-08 time 3.8147e-08
thermal equation solved, solve the next step
KSP final norm of residual 3.85305e-14
KSP final norm of residual 7.55988e-19
6 TS dt 3.8147e-08 time 0.0400001
N-S equation solved, solve the thermal equation,
0 TS dt 3.8147e-08 time 0.
KSP final norm of residual 1.46488e-24
1 TS dt 3.8147e-08 time 3.8147e-08
thermal equation solved, solve the next step
KSP final norm of residual 5.22306e-14
KSP final norm of residual 9.46825e-19
7 TS dt 3.8147e-08 time 0.0400001

I also tried to use such solver for my coupled script, N-S equation and thermal equation are solved simultaneously. It end up with the same divergence problem.

Does the linear solver converge?

I added -ksp_converged_reason and got

Linear solve did not converge due to DIVERGED_ITS iterations 10000
KSP final norm of residual 1.65849e-05
Linear solve did not converge due to DIVERGED_ITS iterations 10000
KSP final norm of residual 1.65849e-05
Linear solve did not converge due to DIVERGED_ITS iterations 10000
KSP final norm of residual 1.65849e-05


Well, then yes, you need to investigate fancier preconditioners.

Is mAL a candidate? In my problem, the block structure of N-S equation is similar, with a buoyancy term and a shifted mass matrix added.

It is worth the try.