srenevey / ode-solvers

Numerical methods to solve ordinary differential equations in Rust.
BSD 3-Clause "New" or "Revised" License
64 stars 26 forks source link

feature: Events through root finding in controller #25

Open CGMossa opened 7 months ago

CGMossa commented 7 months ago

Hey! First, I'd like to say, that this is a great project, and I was investigating the possibility to write something like this myself, but this is way better than what I would have scraped together.

I'd like to open the discussion, if I may, for adding event / callback functions. This was mentioned in #1.

This is available in the R-package desolve and the julia package DifferentialEquations.jl as callbacks.

Currently, I make use of the 2nd point, in that I use this to accurately determine a certain duration using deSolve. E.g.

  deSolve::lsodar(
    times = c(0, Inf),
    rootfunc = 
      # estimate for prevalence - prevalence threshold
      ...
  )

I'd like to be able to do (2), but (1) and (3) are cool to have. It would be nice to collate thoughts, ideas, concerns, about this, and maybe eventually someone could do it? I would very much like to contribute, and if it becomes somewhat clear, what needs to happen, I'd like to do it!

srenevey commented 7 months ago

Hi @CGMossa,

I think it would be a nice addition to implement an event detection mechanism to the crate. I won't have time to work on it myself but feel free to propose an implementation design. For (1) and (2), how is that different than implementing solout for your system?

CGMossa commented 7 months ago

Thanks for the positive reply back! I'm very happy with that. I'm not an expert myself, so I'll take a stab at it.

Right! So with the way I defined deSolve, the system will stop at exactly the root. I will have the exact time in which the event occurred, and not "just" when we crossed a certain threshold, that is mostly dictated by the stepsize in time.

In my work, I use this time as a measure of how long, numerically exactly, the system spent until it reached this condition.