[petsc-users] PETSc using problem

Matthew Knepley knepley at gmail.com
Sun May 11 16:11:53 CDT 2025


On Sun, May 11, 2025 at 4:00 PM Barry Smith <bsmith at petsc.dev> wrote:

>
>    I suppose we could call the postcheck even on failure. Then your first
> check in your postcheck would be on SNESLineSearchReason. What line search
> are you using? You could add the postcheck to all the early
> PetscFunctionReturns() in the line search routine.
>

As I said, I don't think I agree with PostCheck in this scenario.

  Matt


> On May 11, 2025, at 11:50 AM, Matthew Knepley <knepley at gmail.com> wrote:
>
> On Sun, May 11, 2025 at 11:39 AM hj2000--- via petsc-users <
> petsc-users at mcs.anl.gov> wrote:
>
>> 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?
>>
> PostCheck is intended to work on the solution found by the line search.
>
>
>> Do I need to do something else?
>>
> Yes. We do not have a specific hook for failure, because that would make
> it a different line search (one which may not obey the advertised
> properties). Thus we would want your scheme to be its own line search.
>
>   Thanks,
>
>      Matt
>
>
>> 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);
>>
>>
>>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which their
> experiments lead.
> -- Norbert Wiener
>
> https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!deFm6anFdsGG0BfyGak4ewySR2Mh9Pquul08gXi74TZ_mScnmYbiUZXpoeJy_vLlOyZxW0yM2vZTz5m24eDN$ 
> <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!Y6XIK823eTx-iRg60ThDREJsmpqY4jNxIxr-y3_Li6lAA2rs8JvxNjeeUrgfpgbcSCSaRzhBaYiBH_soe98y$>
>
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!deFm6anFdsGG0BfyGak4ewySR2Mh9Pquul08gXi74TZ_mScnmYbiUZXpoeJy_vLlOyZxW0yM2vZTz5m24eDN$  <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!deFm6anFdsGG0BfyGak4ewySR2Mh9Pquul08gXi74TZ_mScnmYbiUZXpoeJy_vLlOyZxW0yM2vZTz334Wg26$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20250511/2ae9e6fb/attachment-0001.html>


More information about the petsc-users mailing list