I would like to know if there is any way to stop the ODE integration after a specific number of detected events. I know that scipy.integrate.solve_ivp allows making an event terminate or not, but I want to know if it’s possible to make it terminate at the n-th event, where n is a integer number bigger than one.
For example, is it possible to compute only the first three interactions with an event and then stop the integration? If this is not possible, is there an alternative library to do it?
I read the official documentation of scipy related with the integration of ODE but I haven't found anything.
Here is an example hack. As suggested in the comments,
wrapped_eventreturns an arbitrary value before the required number of events has been reached, then it starts returning the true event function. (There is a little extra complexity due to sign issues when detecting event crossings.) All you should need to do to use it with your own code is to wrap your event function withwrap_event, that pass the result intosolve_ivp. Respecting theterminalattribute of the event is not requested, but easy to accommodate.