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

Removing particles from sim after a collision #660

Closed ofoofoo closed 1 year ago

ofoofoo commented 1 year ago

I'm trying to implement a custom collision function similar to the my_merge function here: https://rebound.readthedocs.io/en/latest/ipython_examples/User_Defined_Collision_Resolve/

However, when you move to a system with more than 2 planets, the indices of the particles in the simulation get a little jumbled:

image

Preferably, I would like it so that after particle three merges into particle 2, all of the other particles in the simulation shift down by one. Rather, it instead looks like what is currently happening is that particle 3 becomes the new particle 6.

To be more specific, I'm wondering if the following is possible:

Force the merging to always merge a higher index particle into the lower index one + once the merge occurs, all particles with an index greater than the higher index particle shifts up by one.

hannorein commented 1 year ago

You can set the collision_resolve_keep_sorted flag to 1 which should do what you're looking for.

ofoofoo commented 1 year ago

Where should this go? I added the flag to my integration setup but it seems like the issue still persists:

image
hannorein commented 1 year ago

It's a flag in struct reb_simulation.

ofoofoo commented 1 year ago

Ah, I see, thank you!