[petsc-users] Setting an unknown initial guess
Barry Smith
bsmith at petsc.dev
Tue Dec 8 20:45:54 CST 2020
David,
Let me rephrase what you are saying so I understand it.
You have multiple linear solves in time stepping (one linear solve per time step?) and it you call KSPSetInitialGuessNonzero(ksp,PETSC_TRUE); after the first solve then the later solves converge (using the solution to the previous solve as the initial guess for the next solve).
But sometimes the final solution for a particular linear solve happens to be zero, in that case the initial guess for the next solve, of course, is also zero and that solve does not converge.
Is there any way to "fix" these cases so they also get convergence?
Is this a correct description of your situation?
Question: is your matrix A not square, so you are actually solving the normal equations (via LSQR)?
Now I'll try to write it down with simple formula. F() represents whatever computation you perform to get the right hand side for the next timestep linear system.
x_0 given, A' A x_1 = A' F(), ... at some timestep A' Ax_n = A' F() the solution to the normal equations x_n is zero which presumably means A' F() is zero for that solve.
You attempt to solve A' A x_n+1 = A' F() for the next time-step using x_n = 0 as the initial guess and "the solver fails to converge".
What do you mean "fails to converge"? Does it just say the solution is zero, does it just jump around? Does the residual just crawl really really slowly down?
I would first proceed as Matt suggests, call KSPSetOperators(ksp,A,B) where B is obtained with MatMatMult(A,A,...) and use -pc_type lu so now it tries to solve the normal equations with a direct solver for the preconditioner and may be much less dependent on initial guess for the LSQR solve. If this works but Iu is too expensive a preconditioner you can then experiment with other less expensive preconditioners that depend on your problem.
If all you want to do is replace the occasional zero initial guess that comes along with something else you can simply do this, continue with the flag KSPSetInitialGuessNonzero(ksp,PETSC_TRUE); and immediately before each KSPSolve() check the norm of the initial guess, if it is zero then set it to something else. What else you would set it to I don't know, just some VecSetRandom()?
I would go back to the formulation and try to understand what A' F() =0 means and why it would happen and also why an initial guess of zero causes slow or no convergence.
Barry
> On Dec 8, 2020, at 7:58 AM, David Schneider <dav.schneider at tum.de> wrote:
>
> Dear all,
>
> I'm using a KSPLSQR solver without preconditioning and configure the solver once in the beginning. Afterwards, I solve my system multiple times in a time-dependent system and I would like to use an initial guess (from the previous solution). Currently, I use `KSPSetInitialGuessNonzero` for this purpose, but it may happen that the actual guess is zero. If the initial guess is zero, the solver fails to converge, at least with the default configuration. Setting `KSPSetInitialGuess` with `PETSC_FALSE` (which should also be the default) zeros the guess out. Is there a (native) way to preserve the initial guess, but still ensure convergence in the KSPsolver in case the guess is zero?
>
> Thanks in advance,
> David
>
More information about the petsc-users
mailing list