hannorein / rebound

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

Adding particles via Horizons system #767

Closed tamidodo closed 2 months ago

tamidodo commented 2 months ago

Hello, I'm using rebound version 4.3.2 and I was trying to set up a simulation with solar system planets and a meteoroid. Based on the documentation, it would seem that when you add particles and define a mass, the mass should be in solar masses and that holds true for objects where you define their orbital parameters but it seems that when you add particles via the Horizons system, it converts the mass you define to solar masses from kg.

For example, I tried to add the sun using sim.add("Sun", date="2022-04-02 05:01", m=1.0, hash="Sun")

But if I print the status of the simulation, I get back: <rebound.particle.Particle object at 0x17629bf40, m=5.02897844233056e-31 x=-0.00884558873663786 y=0.002565501946066944 z=0.00018562717783423917 vx=-0.00014292114176514488 vy=-0.0005082093685677345 vz=7.460004685606641e-06>

If, however, I add the sun using kg for mass, it then correctly has the mass in solar masses of about 1: sim.add("Sun", date="2022-04-02 05:01", m=1.9891e30, hash="Sun") <rebound.particle.Particle object at 0x17629bec0, m=1.0003141019639716 x=-0.00884558873663786 y=0.002565501946066944 z=0.00018562717783423917 vx=-0.00014292114176514488 vy=-0.0005082093685677345 vz=7.460004685606641e-06>

If that could be updated in the documentation, that would be very helpful as I spent a long time trying to track down why my simulations were going haywire. Or if I'm missing something like needing to set some setting accordingly, please let me know how I can do that. Thanks!

hannorein commented 2 months ago

Hm. Did you manually set the units beforehand? Regardless, if you query a planet or the sun from horizons, you don't need to specify a mass. So just use:

sim.add("Sun", date="2022-04-02 05:01", hash="Sun")
tamidodo commented 2 months ago

No I didn't set the units manually at all. Just running the commands below gives me this result of the simulation interpreting the "m=1.0" as m = 1.0 kg:

sim = rb.Simulation() sim.add("Sun", date="2022-04-02 05:01", m=1.0, hash="Sun"

It's not a bug or anything, just suggesting that the examples in the documentation which show adding Ida from Horizons and specifying the mass in solar masses might need to be updated.

hannorein commented 2 months ago

Ah. Thanks for clarifying! Well, I think this qualifies as a bug. Clearly you'd expect the mass you provide to be the mass of the particle in the end, in whichever units you work. I've pushed a change to the horizon_units branch and I'll merge it in the main branch once the unit tests pass. Thanks again for noticing this!