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


Reply via email to