[petsc-users] PETSc using problem
hj2000 at mail.ustc.edu.cn
hj2000 at mail.ustc.edu.cn
Sun May 11 10:38:47 CDT 2025
Dear Developer:
I am a user of PETSc, and I am using SNESLineSearchSetPostCheck to perform some actions when the line search fails.
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?
My PETSc version is 3.18.6. Below is my code.
auto LineSearchPostCheck = []( SNESLineSearch ls, Vec x, Vec y, Vec w, PetscBool* changed_Y,
PetscBool* changed_W, void* ) {
SNESLineSearchReason lscnv;
SNESLineSearchGetReason( ls, &lscnv );
SNES snes = nullptr;
SNESLineSearchGetSNES( ls, &snes );
SNESConvergedReason cnv;
SNESGetConvergedReason( snes, &cnv );
double lambda = 0.0;
SNESLineSearchGetLambda( ls, &lambda );
PetscPrintf( MPI_COMM_WORLD, "lambda=%lf\n", lambda );
if ( lscnv != SNES_LINESEARCH_SUCCEEDED || lambda < 1e-4 )
{
VecWAXPY( w, -0.1, y, x );
SNESLineSearchSetReason( ls, SNES_LINESEARCH_SUCCEEDED );
*changed_W = PETSC_TRUE;
}
return 0;
};
SNESLineSearchSetPostCheck( ls, LineSearchPostCheck, nullptr);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250511/185321f3/attachment.html>
More information about the petsc-users
mailing list