Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test particles with Tree Collision Detection? #599

Open
r-zachary-murray opened this issue May 23, 2022 · 6 comments
Open

Test particles with Tree Collision Detection? #599

r-zachary-murray opened this issue May 23, 2022 · 6 comments

Comments

@r-zachary-murray
Copy link

Hi All,

I've been having an issue with using rebound's "tree" collision detection with systems with test particles. I find that these systems will integrate normally for a while before suddenly destabilizing - with any orbiting particles moving on straight lines. For a minimum reproducible example see:
https://github.com/r-zachary-murray/rebound_collisions/blob/main/mre_issue.ipynb

I think what is happening is the "tree" collision detection module is shuffling the indices until the central body ends up at an index assigned to a test particle. This causes rebound to ignore its mass and leads to strange behavior. To confirm this I've re-run the simulations using the "direct" collision detection instead, this works as expected. Alternatively, making all 4 particles active also fixes the issue.

https://github.com/r-zachary-murray/rebound_collisions/blob/main/mre_fix1.ipynb
https://github.com/r-zachary-murray/rebound_collisions/blob/main/mre_fix2.ipynb

Hence the question: Is there any way to get around this limitation? Perhaps by identifying active particles with hashes instead of indices so that this problem does not occur?

-Thanks

@hannorein
Copy link
Owner

I'm sorry for the slow response. We were without power for 9 days and I must have missed the notification.

You're right. That doesn't work because the tree algorithm is shuffling particles around whereas the test-particles need to have a fixed index.

As a quick fix, depending on your setup, you could add the gravity from the central body as an "additional force", therefore making all particles test particles.

Of course, the proper way to fix this would be to change the way the reshuffling works. But that would affect almost every logic statement in the tree algorithm. So I hesitate to do that. But at the very least, I should add a warning message to let users know about the issue.

Let me know if this helps. Happy to brainstorm more about possible solutions depending on your specific setup!

Hanno

@r-zachary-murray
Copy link
Author

Hi Hanno,

Thanks for the response, good to see I'm not missing something basic! The real system I'm working with has both massive planets and test particles (~10,000) orbiting a central body - so adding the central body as an additional force wouldn't suffice. Further testing shows that using the "direct" collision detection is only a factor of ~3 slower when run on the full system, which is sufficient for my purposes. Thanks for the help!

@hannorein
Copy link
Owner

Got it. Let me know if speed becomes an issue. It depends on what kind of collisions you're interested in (testparticle-testparticle or planet-testparticle), but there are several hackish solutions out there that I can think of. For example, you could just not add the star and planets to the tree. You'd miss planet-planet and planet-testparticle collisions (or would have to search for them manually). But the tree code wouldn't reshuffle the star or planets.

Which collision detection algorithm are you using? Just the standard TREE code (which checks for overlapping particles) or the LINETREE one (which checks for overlaps along line segments and allows you to use larger timesteps).

@r-zachary-murray
Copy link
Author

I'm using the standard TREE code. Unfortunately, I'm interested in both the testparticle-testparticle and planet-testparticle collisions, but I expect there to be many more of the former and relatively few of the latter, so checking the planet-testparticle collisions manually wouldn't be arduous. Could you tell me more about how one might go about only adding test particles to the tree?

@hannorein
Copy link
Owner

I think it should work if you add particles first that you don't want in the tree, then initialize the tree, then add the test particles:

import rebound
sim = rebound.Simulation()
sim.add(m=1)
sim.add(m=1e-3, a=1)

sim.configure_box(10)
sim.collision = "tree"
sim.add(a=1.3)

@r-zachary-murray
Copy link
Author

Ah I see, that's very simple! I'll give that a try, thanks again for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants