[petsc-users] Inquiry Regarding Callback Implementation for SNES in PETSc

Matthew Knepley knepley at gmail.com
Tue Nov 14 15:37:46 CST 2023


On Tue, Nov 14, 2023 at 3:59 PM Rene Chenard via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Dear PETSc Developers,
>
> I hope this message finds you well. My name is René Chenard, and I am a
> Research Professional at Université Laval. We are currently working on
> implementing a wrapper for the SNES in our project and are seeking guidance
> on incorporating callbacks at different stages of the resolution process.
>
> Specifically, our objective is to implement a callback that triggers at
> the initiation of every nonlinear iteration and another that activates at
> the conclusion of each nonlinear iteration. In our exploration, we
> discovered the potential use of SNESSetUpdate and SNESSetConvergenceTest
> for this purpose.
>
> However, we encountered a challenge with SNESSetUpdate, as it seems to be
> ineffective for the ngmres and anderson solver types, the latter of which
> appears to be based on the implementation of ngmres. We are reaching out to
> seek clarification on whether this behavior is intentional and to explore
> alternative approaches that might better suit our needs.
>
> To facilitate a clearer understanding of our observations, we have
> prepared a reproduction example in the file named test_snes.c. This file
> outlines the specific scenarios where we encountered challenges with
> SNESSetUpdate and provides a context for our inquiries.
>
> Here are our specific questions:
>
> 1. Is SNESSetUpdate designed to function uniformly across all types of
> SNES solvers?
>

Yes, this is our bug in NGMRES. It is fine if you make an MR for this, or
we can do it.


> 2. What would be the recommended approach to implement custom callbacks
> around every nonlinear iteration, especially considering the apparent
> limitations with SNESSetUpdate for certain solver types?
>

That is the right way, we just need to fix NGMRES.


> 3. We observed a discrepancy in the iteration/step numbering between the
> update function (set by SNESSetUpdate) and the convergence function (set by
> SNESSetConvergenceTest). Could you provide clarification on this,
> considering the documentation's description of SNESSetUpdate as the
> function "called at the beginning of every iteration of the nonlinear
> solve"?
>

Update is designed to be called at each iteration. The convergence test
could possibly be called more than that (I think). For example, during line
search you might call the convergence test to decide whether to keep
searching.

What do you want to do at the end of each iterate?

  Thanks,

     Matt


> We genuinely appreciate your expertise in this matter, and your insights
> will be invaluable in guiding our implementation. Thank you in advance for
> your consideration and support.
>
> Warm regards,
>
> —René Chenard
> Research Professional at Université Laval
> rene.chenard.1 at ulaval.ca
>
>

-- 
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://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20231114/291d0664/attachment-0001.html>


More information about the petsc-users mailing list