DiffEqBase.jl
DiffEqBase.jl copied to clipboard
User defined termination condition
Hi, how can I define my own termination condition with the current API? It doesn't look like it's possible but I might be wrong...
For instance, I'd like the solver to terminate when a certain energy is below a tolerance or only check a subset of the state vector.
@avik-pal I don't think there is a way to give an arbitrary function in the new termination conditions?
Alright. If I'd like to add this, two options come to mind:
- Changing the callback handling so that the solve function checks if a user defined
TerminateSteadyStatecallback is passed as an argument. If yes, use it. If not, use the one from thealg. - Adding a dispatch to
_has_convergedfor a custom termination mode
I think option 1 might be easier to implement, but would maybe not be so consistent with the API? If you think it's an alright idea, I would know how to write up a PR for option 1.
But I don't know if adding this would have any benefits over just using ODEProblem with infinite timespan and a TerminateSteadyState condition...
I think it's reasonable to allow for a function form in the new termination conditions. See https://docs.sciml.ai/NonlinearSolve/stable/basics/TerminationCondition/ . But they are much more comprehensive now, so do try and see if the new conditions better suit your problem.