bluescarni / heyoka

C++ library for ODE integration via Taylor's method and LLVM
https://bluescarni.github.io/heyoka/
Mozilla Public License 2.0
193 stars 12 forks source link

Does heyoka support external dynamic input of the ODE system? #417

Open gaowutong opened 3 weeks ago

gaowutong commented 3 weeks ago

Hello and thanks for this great project!

I notice that heyoka supports runtime parameters in its expression system. But what if the parameters has different values at different time steps? How can I handle this?

This is common in many cases. A particular scenario is propagating It requires to read planeteary ephemeris data and get the position of some planets at each time step to compute their perturbations. But it seems heyoka compiles the expression at the beginning and does not allow to change it during integration.

bluescarni commented 2 weeks ago

Hi @gaowutong

You can change the values in the parameters array at any time you want. The parameters array is accessible from a taylor_adaptive object via member functions such as get_pars() (for read-only access), get_pars_data() (for read-write access) and others, see here:

https://github.com/bluescarni/heyoka/blob/master/include/heyoka/taylor.hpp#L549

For instance, you can change the values in the parameters array at the end of each timestep via a step callback, explained here:

https://bluescarni.github.io/heyoka/tut_adaptive.html#time-limited-propagation

Another option is to use the event detection system - specifically, a terminal event which stops the integration whenever you need to change the parameters' values via an event callback:

https://bluescarni.github.io/heyoka/tut_events.html#terminal-events

Please let me know if you need further help/explanations.