hannorein / rebound

💫 An open-source multi-purpose N-body code.
https://rebound.readthedocs.io/
GNU General Public License v3.0
824 stars 218 forks source link

Synchronizing position/velocity in custom merger routine #625

Closed MiguelASMAstro closed 10 months ago

MiguelASMAstro commented 1 year ago

Hi all,

I'm running some simulations where I detect if test particles are crossing through a planet's radius of influence. I have written a custom merger routine that essentially prints out the time of collision and hash of the test particle, then deletes the test particle from the simulation.

I am using the WHCKL integrator with safe mode turned off as is the default and I find that I get the following runtime warning RuntimeWarning: Recalculating coordinates but pos/vel were not synchronized before. warnings.warn(msg[1:], RuntimeWarning)

So when using the WH integrators, is it necessary to set sim.ri_whfast.recalculate_coordinates_this_timestep = 1 somewhere during the merger routine? And if so, where?

For reference, here's my code: https://github.com/MiguelASMAstro/stableplanets/blob/master/solarsystem.py

Thanks

hannorein commented 1 year ago

If you just remove a particle, you can ignore the warning. However, if you change the coordinates of a particle within your merger routine and the particle stays in your simulation, then you need to be careful about when/which coordinate gets modified. In short: Use synchronize() before you modify anything. Then modify any particle normally. The rest should be taken care of automatically.

MiguelASMAstro commented 1 year ago

Great, thanks!