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
However, if the initial guess in not 0, how shall we define this?


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
-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)
||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 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).