2011/1/27 Gong Ding <span dir="ltr"><<a href="mailto:gdiso@ustc.edu">gdiso@ustc.edu</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br>
I sometimes try to use iterative solvers in the SENS.<br>
However, it may fail to convergence for some difficult problems.<br>
SNES will report SNES_DIVERGED_LINEAR_SOLVE for this situation.<br>
<br>
Is it possible to add a hook function here?<br>
i.e. I'd like to change the linear solver to LU and solve the<br>
Newton step again instead of break the nonlinear solver.<br></blockquote><div><br></div><div>I believe the complexity is best controlled by changing the linear solver rather than adding</div><div>another generic hook to the nonlinear solver. You can create your own KSP. It holds a KSP</div>
<div>which you set from options and another which is LU. If the first returns kspreason < 0, you</div><div>solve with the second.</div><div><br></div><div>A slightly easier, but more hacky way to do this is to override the ConvergenceTest for your</div>
<div>current KSP, so that it solves with LU on failure.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Here is the code from ls.c which report the SNES_DIVERGED_LINEAR_SOLVE<br>
<br>
if (kspreason < 0) {<br>
if (++snes->numLinearSolveFailures >= snes->maxLinearSolveFailures) {<br>
ierr = PetscInfo2(snes,"iter=%D, number linear solve failures %D greater than current SNES allowed, stopping solve\n",snes->iter,snes->numLinearSolveFailures);CHKERRQ(ierr);<br>
snes->reason = SNES_DIVERGED_LINEAR_SOLVE;<br>
break;<br>
}<br>
}<br>
The hook function may be added befour the break.<br>
<br>
Regards,<br>
<font color="#888888"><br>
Gong Ding<br>
<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener<br>