Initial guess for a PETSc solver

Dear all,

When we use a PETSc solver for a linear system Ax=b, such as

set(A, sparams = "-ksp_monitor -ksp_type fgmres -ksp_converged_reason -ksp_atol 1.e-20 -ksp_rtol 1.0e-8 -ksp_max_it 500 -pc_type fieldsplit -pc_fieldsplit_type schur "
	+ "-fieldsplit_velocity_pc_type gamg -fieldsplit_velocity_pc_gamg_sym_graph true -fieldsplit_pressure_ksp_max_it 5 "
	+ "-fieldsplit_pressure_pc_type jacobi -fieldsplit_velocity_ksp_type preonly -pc_fieldsplit_schur_fact_type full",
	fields = ux[], names = names);

How can we specify an initial guess? such as using the solution of the previous time step rather than always iterating from 0.

In addition, how can we define the stop criterion such as
||Ax_n- b||/||b|| < tol.

If the tinitial guess is 0, this is equivalent to define
-ksp_rtol<tol
However, if the initial guess in not 0, how shall we define this?

Best,
Yongxing

Put what you want in x and use the option -ksp_initial_guess_nonzero (KSPSetInitialGuessNonzero).
Tolerances can be adjusted using options as well (KSPSetTolerances).

Thank you. Regarding the tolerance to stop the iteration:
I know
-ksp_atol for ||Ax_n- b|| < tol
and
-ksp_rtol for ||Ax_n- b|| / ||Ax_0- b|| < tol

However, I cannot find one key word to do:
||Ax_n- b|| / ||b|| < tol (equivalent to use -ksp_rtol when the initial guess x_0= 0)
or
||Ax_{n+1}- b|| / ||Ax_n- b|| < tol

Do you have an idea?

Your equation for -ksp_rtol is wrong, please have a look at page 68 of https://petsc.org/release/docs/manual/manual.pdf. The fact that your initial guess is zero or not does not change how these equations are evaluated, b is always b, x_n is always x_n (x_0 is either 0 or what you supply if you use -ksp_initial_guess_nonzero).

Dear @prj ,

I just realized that when I am solving my linear system with reusing the LU factorization (discussed in this topic, I am not using the option -ksp_initial_guess_nonzero true option, with which the solution time can be reduced even further. However, when I am trying to switch on and off -ksp_initial_guess_nonzero similarly to ksp_reuse_preconditioner, I get a strange error message

[0]PETSC ERROR: Running KSP of preonly doesn’t make sense with nonzero initial guess
you probably want a KSP type of Richardson

I also made an MWE which reproduces this behavior with some small modifications to the Stokes-PETSc example. Could you please take a look at this, and suggest a possible solution to this problem?
stokes-2d-PETSc.edp (1.6 KB)

Thanks
András

Thanks for the reproducer. That’s an upstream issue, which should hopefully be addressed by KSP: check -ksp_initial_guess_nonzero first (!4760) · Merge requests · PETSc / petsc · GitLab.

1 Like

Thanks for the quick fix. I will keep an eye on the merge request and try this out as soon as possible.

Dear @prj ,

Sorry for bothering once again. I try to circumvent the issue in the meantime with defining an additional Mat to which no KSP parameters are attached, and using that to override the ksp param. However, when I copy a Mat, the partition of unity (Mat.D) does not seem to be copied. I also attach a reproducer. I can just store the partition of unity in a vector of course, but I am curious whether this is intentional, or is this a bug?
partofUnity.edp (674 Bytes)

This is intentional. When you copy a Mat (using either the constructor Mat B(A) or B = A), the domain decomposition information (such as the partition of unity) from A is not carried over to B.

Thanks for the info.

Furthermore, thanks for the fix in PETSc - I just compiled the most recent version in which the merge is accepted, and setting on and off -ksp_initial_guess_nonzero works perfectly!