<style class="ke-style">
[list-style-type] {padding-left:20px;list-style-position:inside}
[list-style-type] li {margin:0}
[list-style-type] li:before, span.ke-list-item-matter {font-family:"sans serif",tahoma,verdana,helvetica}
[list-style-type] li p,[list-style-type] li h1,[list-style-type] li h2,[list-style-type] li h3,[list-style-type] li h4,[list-style-type] li h5,[list-style-type] li div,[list-style-type] li blockquote{display:inline;word-break:break-all}
[list-style-type] li table {display:inline-block;vertical-align:top}
p{margin:0}
td {word-break: break-word}
.default-font-1746977456402{
font-size:14px;
}
</style><div class="default-font-1746977456402" dir="ltr"><p style="text-wrap-mode:wrap;"><span style="text-wrap-mode:nowrap;">Dear Developer:</span></p><p style="text-wrap-mode:wrap;"><span style="text-wrap-mode:nowrap;">   I am a user of PETSc, and I am using <code>SNESLineSearchSetPostCheck</code> to perform some actions when the line search fails. </span></p><p style="text-wrap-mode:wrap;"><span style="text-wrap-mode:nowrap;">However, it seems that this function is only called when the line search is successful. Why is that? Do I need to do something else? </span></p><p style="text-wrap-mode:wrap;"><span style="text-wrap-mode:nowrap;">My PETSc version is 3.18.6. Below is my code.</span></p><blockquote style="padding-left:5px;margin-left:5px;border-left:2px solid #B6B6B6;"><p style="text-wrap-mode:wrap;"><span style="text-wrap-mode:nowrap;"></span><span style="text-wrap-mode:nowrap;"> </span></p><p>        auto LineSearchPostCheck = []( SNESLineSearch ls, Vec x, Vec y, Vec w, PetscBool* changed_Y,</p><p>                                       PetscBool* changed_W, void* ) {</p><p>            SNESLineSearchReason lscnv;</p><p>            SNESLineSearchGetReason( ls, &lscnv );</p><p>            SNES snes = nullptr;</p><p>            SNESLineSearchGetSNES( ls, &snes );</p><p>            SNESConvergedReason cnv;</p><p>            SNESGetConvergedReason( snes, &cnv );</p><p>            double lambda = 0.0;</p><p>            SNESLineSearchGetLambda( ls, &lambda );</p><p>            PetscPrintf( MPI_COMM_WORLD, "lambda=%lf\n", lambda );</p><p>            if ( lscnv != SNES_LINESEARCH_SUCCEEDED || lambda < 1e-4 )</p><p>            {</p><p>                VecWAXPY( w, -0.1, y, x );</p><p>                SNESLineSearchSetReason( ls, SNES_LINESEARCH_SUCCEEDED );</p><p>                *changed_W = PETSC_TRUE;</p><p>            }</p><p>            return 0;</p><p>        };</p><p>        SNESLineSearchSetPostCheck( ls, LineSearchPostCheck, nullptr);</p><p style="text-wrap-mode:wrap;"><span style="text-wrap-mode:nowrap;"></span><br></p></blockquote></div>