Access SNESMonitorSet in PETSc plugin

When using TSSolve(), we can define custom monitors using TSMonitorSet() as in: examples/hpddm/heat-TS-2d-PETSc.edp.
Relevant source code here.

Is there already an implemented approach to do something similar with SNESMonitorSet() when using SNESSolve()? I want to avoid writing such monitors within the residual function as I am using quasi-Newton methods which evaluate the residual multiple times per iteration.
I wonder if a solution similar to the TS approach might introduce conflicts here since the current implementation already uses SNESConvergenceTest()?

I don’t foresee any issue using both a custom monitor and a custom convergence test.

Ok, but wouldn’t a naive copy of the TS monitor logic introduce an issue here, since the custom convergence monitor is linked to the syntax monitor = …? Are there any examples I can test with that use a custom convergence test?

That’s a good point. I’m not sure why the current code use the variable name monitor for something else that… setting a custom monitor. There should be a new named parameter, so then it would be possible to have both a custom monitor and convergence test.

OK. I’ll draft a PR that repurposes monitor = ... for its stated purpose and adds a new optional parameter convergence = ... to support custom convergence tests. This will obviously break anything that uses custom SNES convergence monitors through the existing interface, however.

I’d appreciate it. I’ll take the blame for any breakage :slight_smile:

1 Like

Just submitted here. Please let me know if you have any feedback or comments.